我正在創建圖像查看器類應用程序。我在Windows上並使用.Net拖拽時突出顯示矩形區域
在我的應用程序中,我試圖在拖動時突出顯示特定區域。 我已經創建了一個矩形。
Rectangle areaRect = new Rectangle(100,100, 300, 300);
Point ptOld = new Point(0, 0);
Pen rectPen = new Pen(Brushes.White, 3);
protected override void OnPaint(PaintEventArgs e)
{
Graphics dcPaint = e.Graphics;
dcPaint.DrawRectangle(rectPen, areaRect);
}
現在我正在拖動這個矩形區域以及我的鼠標移動。
protected override void OnMouseMove(MouseEventArgs e)
{
Point ptNew = new Point(e.X, e.Y);
int dx = ptNew.X - ptOld.X;
int dy = ptNew.Y - ptOld.Y;
areaRect.Offset(dx, dy);
MoveRect(ptNew);
ptOld = ptNew;
}
在這裏,我想直到這點是工作的罰款待着這個矩形與我的鼠標
void MoveRect(Point point)
{
Graphics grfxClient = CreateGraphics();
Rectangle tempRectangle = new Rectangle(areaRect.Left, areaRect.Top, areaRect.Width, areaRect.Height);
grfxClient.DrawRectangle(rectPen, tempRectangle);
this.Invalidate();
grfxClient.Dispose();
}
我的代碼。 現在我想將INVERSE拖拽區域(拖拽區域之外的區域)變暗,我的意思是這個矩形內的區域應該在拖拽時突出顯示。
任何想法如何繼續。
謝謝。
-Pankaj
感謝盧卡斯,它的工作正是我所需要的。 是的,我已經在自定義圖片框類的頂部創建了這個矩形,我不僅移動了這個矩形,而且還能夠完美調整它的大小(保持其中一個角) 再次感謝。 – Pankaj 2012-04-10 19:38:56
我很高興它幫助:)。如果您能將我的答案標記爲正確,我將不勝感激:)。 – 2012-04-10 20:07:48