0
我有一个WinForm应用程序,该应用程序在PictureBox中显示图像,该图像具有允许用户通过单击和拖动在图像上绘制矩形的附加功能。 矩形的位置,高度和宽度保存到磁盘。如何在WinForm应用程序中的正确位置绘制矩形
当再次查看图像时,我想自动在图像上的相同位置重绘该矩形。
然而,当我重绘它时,高度和宽度都很好,但位置总是关闭。
位置在MouseDown事件被捕获,像这样
private void pbSample_MouseDown(object Sender, MouseEventArgs e)
{
if (SelectMode)
{
StartLocation.X = e.X;
StartLocation.Y = e.Y;
//later on these are saved as the location of the rectangle
}
}
而且我重绘像这样
public void DrawSelectedArea(Rectangle rect)
{
Graphics g = this.pbSample.CreateGraphics();
Pen p = new Pen(Brushes.Black);
g.DrawRectangle(p, rect);
}
鉴于从mouseDown事件如何在捕捉到的MouseEventArgs位置可我计算正确的位置来重绘我的矩形?