DrawLine消失了

CaongZaong 2009-04-15 04:10:17
Graphics g = this.panel1.CreateGraphics();
Pen pen = new Pen(Color.Red,2);
Point oldPoint = new Point();
oldPoint.X = oldbtn.Location.X + oldbtn.Width;
oldPoint.Y = oldbtn.Location.Y + oldbtn.Height / 2;
Point newPoint = new Point();
newPoint.X = newbtn.Location.X;
newPoint.Y = newbtn.Location.Y + oldbtn.Height / 2;
g.DrawLine(pen, newPoint, oldPoint);
为两个控件之间画上线 失去焦点后 线消失了

请问这个怎么解决呢?
...全文
335 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cja03 2009-04-15
  • 打赏
  • 举报
回复
为两个控件之间画上线 失去焦点后 线消失了
-------------------------------------
因为控件失去焦点,会刷新。如果你的画线操作没有和刷新挂勾的话,之前的线就不再出现。

可以使用panel.OnPaint事件。
Harvey_He 2009-04-15
  • 打赏
  • 举报
回复

public Form2()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2Paint);
}

private void Form2Paint(object sender, PaintEventArgs e)
{
Graphics g = this.panel1.CreateGraphics();
Pen pen = new Pen(Color.Red,2);
Point oldPoint = new Point();
oldPoint.X = oldbtn.Location.X + oldbtn.Width;
oldPoint.Y = oldbtn.Location.Y + oldbtn.Height / 2;
Point newPoint = new Point();
newPoint.X = newbtn.Location.X;
newPoint.Y = newbtn.Location.Y + oldbtn.Height / 2;
g.DrawLine(pen, newPoint, oldPoint);

}

Steve 2009-04-15
  • 打赏
  • 举报
回复
把做图的语句放到OnPaint里
protected override void OnPaint( PaintEventArgs e )
{
zgke 2009-04-15
  • 打赏
  • 举报
回复
1 放到Paint里
private void Form1_Paint(object sender, PaintEventArgs e)
{

}

2 或则你绘制到图片上贴背景图.

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧