可以使用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