始终可见图纸上的图纸

时间:2014-03-03 14:41:01

标签: c# winforms graphics

我想在winform上绘制始终可见的交叉图片框。我知道要使用Graphics和它的方法DrawLine。但问题是,画十字架隐藏在图片框后面。此文本框将不断刷新,此交叉应始终可见。 你有解决方案吗?

这是代码:

Point picBoxLocation = pictureBox.Location;
Size picBoxSize =  pictureBox.Size;

Pen myPen = new Pen(System.Drawing.Color.Red, 5);

Point left = new Point(picBoxLocation.X, picBoxSize.Height/2);
Point right = new Point(picBoxLocation.X+picBoxSize.Width, picBoxSize.Height / 2);
Point up = new Point((picBoxLocation.X + picBoxSize.Width) / 2, picBoxLocation.Y);
Point bottom = new Point((picBoxLocation.X + picBoxSize.Width) / 2, (picBoxLocation.Y+picBoxSize.Height)/2);

Graphics graphics = this.CreateGraphics();
graphics.DrawLine(myPen, left,  right);
graphics.DrawLine(myPen, up, bottom);

1 个答案:

答案 0 :(得分:0)

尝试在OnPaint回调中获取Graphics对象:

protected override void OnPaint(PaintEventArgs e)
{
   base.OnPaint(e);
   e.Graphics.DrawLine(...);
}