【发布时间】:2011-11-16 18:59:00
【问题描述】:
我正在尝试在 UserControl 控件上使用画笔进行绘制。我可以画线、圆和矩形。我不完全明白为什么我不能用画笔画画。下面的代码只让我指向 MouseDown,然后它移动到 MouseUp 中设置的位置。在 MouseMove 期间没有绘制任何内容。我想我不明白这里的一些基本规则。
此代码适用于行:
public override void Draw(Graphics graphics) {
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphics.DrawLine(new Pen(this.Color, this.PenSize), startPoint, endPoint);
}
这段代码我正在尝试适配刷机:
public override void Draw(Graphics graphics) {
if (this.bitmap != null) {
graphics = Graphics.FromImage(this.bitmap);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphics.DrawEllipse(new Pen(this.Color, this.PenSize), startPoint.X, startPoint.Y,
this.PenSize, this.PenSize);
graphics.DrawImage(this.bitmap, 0, 0);
}
}
此代码重绘对象列表:
private void UserControl_Paint(object sender, PaintEventArgs e) {
if (ObjectsList != null) {
ObjectsList.Draw(e.Graphics);
}
}
正如代码所示,我试图在点状线条绘制之前和之后抓取位图图像。我应该用其他方式吗?
【问题讨论】: