在表单上始终可见的绘图



我想在winform上画出始终可见的交叉图片框。我知道使用图形和它的方法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);

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

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

相关内容

  • 没有找到相关文章

最新更新