C#绘图中,如何实现橡皮线的效果。 MFC里面要用到SetROP2,但是C#里面没有。实现类似橡皮线的效果。具体来说,如何实现,随着鼠标的移动画矩形线(及时删除原来的矩形框),松开鼠标时显示最后状态下的矩形框? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GDI+的话,没有这个功能如果要用,就得通过API调用GDI接口 不知道你要怎么画 最简单的方法 ControlPaint.DrawFocusRectangle 你可以参考 这个是画一次记录下 矩形 下次画的时候在绘制一个透明的矩形http://blog.csdn.net/zgke/archive/2009/03/04/3956936.aspx 这是个DrawReversibleFrame的例子: public partial class Form1 : Form{ Point startPoint = new Point(-1, -1); Rectangle lastRect = Rectangle.Empty; List<Rectangle> rectangles = new List<Rectangle>(); public Form1() { InitializeComponent(); } protected override void OnMouseDown(MouseEventArgs e) { this.startPoint = this.PointToScreen(e.Location); } protected override void OnMouseMove(MouseEventArgs e) { if (this.startPoint.X >= 0) { Point current = this.PointToScreen(e.Location); Size size = new Size(current.X - startPoint.X, current.Y - startPoint.Y); ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //擦旧 lastRect = new Rectangle(startPoint, size); ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //画新 } } protected override void OnMouseUp(MouseEventArgs e) { if (this.startPoint.X >= 0) { ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //擦 this.startPoint.X = -1; this.rectangles.Add(Normalize(this.RectangleToClient(lastRect))); this.lastRect = Rectangle.Empty; this.Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { foreach (Rectangle rect in this.rectangles) { e.Graphics.DrawRectangle(Pens.Black, rect); } } private Rectangle Normalize(Rectangle rect) { if (rect.Width < 0) { rect.X += rect.Width; rect.Width = -rect.Width; } if (rect.Height < 0) { rect.Y += rect.Height; rect.Height = -rect.Height; } return rect; }} 4楼的方法很好 ,不过这个简易画板也很不错,有画直线,画椭圆,画矩形,等等 http://download.csdn.net/source/1149352 在vs 2012里,textbox.textmode新增了不少属性,比如Email属性,怎么用? 悲哀,想得到却做不到!还有人能完成吗? 创建Thread可以不用委托? C# DataSet使用ReadXml方法的问题 一个socket和httpresponse的问题 加入了updatapanel,如何保持dropdownlist已选择的值 求数组中,出现最多且最大的一个 如何让TextBox响应回车键??多谢各位朋友指教 求助~窗体问题~! 通过Xml配置文件 在Execl中读取数据 并把想要的数据存在数据库中 propertyGrid展开的问题 c/s结构聊天程序如何在广域网中运行?
你可以参考 这个是画一次记录下 矩形 下次画的时候在绘制一个透明的矩形
http://blog.csdn.net/zgke/archive/2009/03/04/3956936.aspx
public partial class Form1 : Form
{
Point startPoint = new Point(-1, -1);
Rectangle lastRect = Rectangle.Empty;
List<Rectangle> rectangles = new List<Rectangle>(); public Form1()
{
InitializeComponent();
} protected override void OnMouseDown(MouseEventArgs e)
{
this.startPoint = this.PointToScreen(e.Location);
} protected override void OnMouseMove(MouseEventArgs e)
{
if (this.startPoint.X >= 0)
{
Point current = this.PointToScreen(e.Location);
Size size = new Size(current.X - startPoint.X, current.Y - startPoint.Y); ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //擦旧
lastRect = new Rectangle(startPoint, size);
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //画新
}
} protected override void OnMouseUp(MouseEventArgs e)
{
if (this.startPoint.X >= 0)
{
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed); //擦
this.startPoint.X = -1; this.rectangles.Add(Normalize(this.RectangleToClient(lastRect)));
this.lastRect = Rectangle.Empty;
this.Invalidate();
}
} protected override void OnPaint(PaintEventArgs e)
{
foreach (Rectangle rect in this.rectangles)
{
e.Graphics.DrawRectangle(Pens.Black, rect);
}
} private Rectangle Normalize(Rectangle rect)
{
if (rect.Width < 0) { rect.X += rect.Width; rect.Width = -rect.Width; }
if (rect.Height < 0) { rect.Y += rect.Height; rect.Height = -rect.Height; }
return rect;
}
}
不过这个简易画板也很不错,有画直线,画椭圆,画矩形,等等
http://download.csdn.net/source/1149352