在图片框中绘制矩形C#

时间:2016-08-10 13:07:21

标签: c# draw picturebox drawrectangle

我有一个应用程序,在pictureBox中显示不同的图像。还有一些其他图片框做其他事情,我想保留默认的绘画方法。 当图像正确时,我必须绘制一个绿色矩形,当图像不正确时,我不必做任何事情。

我已经看到需要覆盖绘制方法以绘制矩形,但如果我覆盖该方法,它将始终绘制绿色矩形。

编辑:

我写过这个方法:

private void pictureBox_Paint(object sender, PaintEventArgs e)
{            
    Rectangle rect = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);
    e.Graphics.DrawRectangle(new Pen(Color.Green, 20), rect);
}    

我打电话将事件添加到它:

pbFrontView.Paint += pictureBox_Paint;
pbLeftView.Paint += pictureBox_Paint;

所以,我有很多图片框和不同的图片(这是我的主要功能)

if(drawRectanglePbFront)
    //Draw rectangle in pbFrontView
if(drawRectanglePbLeft)
    //Draw rectangle in pbLeft
...

有没有办法知道哪个pinture框已经调用" pictureBox_Paint" ?如果,是的,我可以移动" if(drawRectanglePbFront)..."在" pictureBox_Paint"内部并管理那里的一切

0 个答案:

没有答案