可以使用ControlPaint
方法作画的可逆矩形/帧
ControlPaint.FillReversibleRectangle
MSDN
和
ControlPaint.DrawReversibleFrame
MSDN
这里是一个小的伪代码方法例如
private void DrawReversibleRectangle(int x, int y) {
// Hide the previous rectangle by calling the methods with the same parameters.
var rect = GetSelectionRectangle(this.PointToScreen(this.reversibleRectStartPoint), this.PointToScreen(this.reversibleRectEndPoint));
ControlPaint.FillReversibleRectangle(rect, Color.Black);
ControlPaint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Dashed);
this.reversibleRectEndPoint = new Point(x, y);
// Draw the new rectangle by calling
rect = GetSelectionRectangle(this.PointToScreen(this.reversibleRectStartPoint), this.PointToScreen(this.reversibleRectEndPoint));
ControlPaint.FillReversibleRectangle(rect, Color.Black);
ControlPaint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Dashed);
}
你会做Microsoft画图究竟是干什么的,看一下背景图像,并确定你应该使用的颜色。请注意,有些颜色与自己的颜色相反。我会看看开源项目Paint.NET的想法。这与WinForms无关,真正的解决方案是扩展自己的能力,默认的方法不会达到你想要的。 – 2011-12-14 18:50:10
@Rhhound:好的,解决方案需要在Winforms中实现,所以解决方案必须与它有关。即使我查看背景图片,我也不确定如何在winforms绘图函数中将这些信息与API一起使用。我也看了Paint.Net的许可证。它不允许创建派生作品,因此我不确定查看其源代码并“获得灵感”是否是一个好主意。 PS:感谢关于颜色的提示,它们有自己的对立面。我将在考虑解决方案时考虑这一点。 – alokoko 2011-12-14 19:07:57