请问各位大师,如何在c#工程中不使用第三方插件或组件实现多图层的处理? 多图层的处理不使用第三方插件或组件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 多个图层实际上可以是多次绘图叠加,而上层的透明分量,决定下层透出的程度。比如下例,上层圆圈部分有个从透明到紫色的渐变(Color.Transparent -> Color.Violet)。你可以观测俩个图层的叠加效果。public partial class Form1 : Form{ public Form1() { InitializeComponent(); this.DoubleBuffered = true; this.Load += delegate { using (Graphics gb = Graphics.FromImage(background)) using (Graphics gf = Graphics.FromImage(foreground)) using (LinearGradientBrush brush = new LinearGradientBrush(Point.Empty, new Point(200, 200), Color.Transparent, Color.Violet)) { gb.CopyFromScreen(Point.Empty, Point.Empty, background.Size); gf.FillEllipse(brush, new Rectangle(Point.Empty, new Size(200,200))); gf.DrawString("用上下左右键来移动前景", this.Font, Brushes.Black, new PointF(20, 100)); } }; this.KeyDown += delegate(object sender, KeyEventArgs e) { Point offset = Point.Empty; switch (e.KeyCode) { case Keys.Left: offset.X -= 5; break; case Keys.Right: offset.X += 5; break; case Keys.Up: offset.Y -= 5; break; case Keys.Down: offset.Y += 5; break; } if (offset != Point.Empty) { Rectangle oldRect = this.rect; this.rect.Offset(offset); this.Invalidate(Rectangle.Union(oldRect, this.rect)); } }; } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawImage(background, this.ClientRectangle); // 先画下层 e.Graphics.DrawImage(foreground, rect); // 再叠加上层... } Rectangle rect = new Rectangle(50, 50, 200, 200); Bitmap background = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Bitmap foreground = new Bitmap(200, 200);} WPF 和 Silverlight 是专门针对 2d 甚至 3d 富媒体、动画、交互操作程序进行开发的平台,并且你要熟练使用 Blend 工具(而不仅仅是 vs 工具)。winform 不是,在winform下如果你想开发一个专业点的上图系统,你自然只能想到“第三方”。 例如这个组织结构图程序,http://developer.51cto.com/art/201207/346850.htm,它没有纠结在底层,只是把坐标计算清楚就行了,其它的绘图部分用 silverlight(wpf代码基本上完全一样) 就搞定了。支持用户交互操作,例如拖放等等!如果你只是开始研究“绘图底层”的代码,你何年何月才能开始真正开始这样一个小程序的开发呢?而这个例子是非常简单的。稍微复杂一点的程序,例如给领导看的辅助决策系统,肯定比这个复杂100倍,需要有几十种类、上千个业务图层(在WPF/Silverlight中其实不叫图层,而叫控件)叠加在画布上,并且支持用户的命中、拖放等等交互操作,支持根据各种远程通讯而驱动的控件状态变化(例如一个抢救车辆掉头行进、或者一个地下管线压力和方向的实时变化)。相当于一个简单的游戏了。如果你只会 winform,然后又说“不用第三方”,你何年何月才能开发一个简单的产品呢?在开发桌面程序方面,我们可以没有程序员,但不存在只会winform的程序员。 实际上,你需要的不是“第三方”,而是一个2d动画系统的框架。比如说你创建一个Polygon对象,然后扔给画布当中,然后你在polygon对象的每一个拐点上放上一个动画闪烁的Circle对象,然后捕获每一个圆点的拖放操作,拖放时自动修改(编辑)Polygon 的外边,并且实时看到用户拖放修改Polygon的各个拐点的交互界面。这一切需要你写多少代码?写100行代码已经算是不少了。绝不要再使用没有生产力的编程工具平台去“玩一玩儿底层”了,要以生产力来选择开发工具。 大师,按照您写的试了一下,但是找不到LinearGradientBrush这个呢? GDI+绘制,N层也没有问题。甚至缩放、移动,点击交互相应等等 datatable remove移除列问题。 数据库查询问题(改错) SQL设置主键问题 帮忙把C代码转VB.Net的,谢谢 分词查询逻辑? vs.net2005提示帮助更新正在进行 C#怎么能像Delphi那样按Control键就能看到某个方法的源代码啊? 我的ASP.NET上传程序中上传文件大小为什么不能超过4M C#无边界窗体的移动 在C#中如何进行OpenGL应用的开发? C#反编译工具 wpf中获取xmal上的button后,但是不能对其操作,界面上不能正常显示操作button
比如下例,上层圆圈部分有个从透明到紫色的渐变(Color.Transparent -> Color.Violet)。你可以观测俩个图层的叠加效果。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
this.Load += delegate
{
using (Graphics gb = Graphics.FromImage(background))
using (Graphics gf = Graphics.FromImage(foreground))
using (LinearGradientBrush brush = new LinearGradientBrush(Point.Empty, new Point(200, 200), Color.Transparent, Color.Violet))
{
gb.CopyFromScreen(Point.Empty, Point.Empty, background.Size);
gf.FillEllipse(brush, new Rectangle(Point.Empty, new Size(200,200)));
gf.DrawString("用上下左右键来移动前景", this.Font, Brushes.Black, new PointF(20, 100));
}
};
this.KeyDown += delegate(object sender, KeyEventArgs e)
{
Point offset = Point.Empty;
switch (e.KeyCode)
{
case Keys.Left: offset.X -= 5; break;
case Keys.Right: offset.X += 5; break;
case Keys.Up: offset.Y -= 5; break;
case Keys.Down: offset.Y += 5; break;
}
if (offset != Point.Empty)
{
Rectangle oldRect = this.rect;
this.rect.Offset(offset);
this.Invalidate(Rectangle.Union(oldRect, this.rect));
}
};
} protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(background, this.ClientRectangle); // 先画下层
e.Graphics.DrawImage(foreground, rect); // 再叠加上层...
} Rectangle rect = new Rectangle(50, 50, 200, 200);
Bitmap background = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Bitmap foreground = new Bitmap(200, 200);
}
大师,按照您写的试了一下,但是找不到LinearGradientBrush这个呢?