画上面板允许自动滚屏 [英] Paint on panel allowing auto scroll

查看:162
本文介绍了画上面板允许自动滚屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行那些想要绘制在面板线的应用程序。但小组必须是自动滚动的,因为它的大小可以在运行时扩展。我用的面板漆方法为below.When我运行它绘制线条程序,但是当我向下滚动面板线得到crashes.How我能避免呢?



 私人无效panel1_Paint(对象发件人,PaintEventArgs的E)
{
this.DoubleBuffered = TRUE;
笔P =新笔(Color.Red);

的for(int i = 0;我小于10;我++){$​​ B $ B e.Graphics.DrawLine(P,(新点(我* 40,0)),(新点(ⅰ* 40,60 * 40)));
}
的for(int i = 0; I< 60;我++)
{
e.Graphics.DrawLine(P,(新点(0,I * 40) ),(新点(10 * 40,我* 40)));
}
}


解决方案

我会认为得崩溃实际上并不意味着你的代码崩溃。你需要通过滚动量来抵消图。这很容易做到:

 私人无效panel1_Paint(对象发件人,PaintEventArgs的E){
e.Graphics.TranslateTransform( panel1.AutoScrollPosition.X,panel1.AutoScrollPosition.Y);
//等
// ...
}


I'm implementing an application which want to draw lines in the panel. But the panel must be auto scrolled as it size can be expand at run time. The panel paint method I have used is as below.When I run the program it draws lines, but when I scroll down the panel the lines get crashes.How can I avoid that?

private void panel1_Paint(object sender, PaintEventArgs e)
{
  this.DoubleBuffered = true;
  Pen P = new Pen(Color.Red);

  for (int i = 0; i < 10; i++) {
    e.Graphics.DrawLine(P, (new Point(i * 40, 0)), (new Point(i * 40, 60 * 40)));
  }
  for (int i = 0; i < 60; i++)
  {
    e.Graphics.DrawLine(P, (new Point(0, i  *40)), (new Point(10 * 40, i * 40)));
  }
}

解决方案

I'll assume that "get crashes" doesn't actually mean that your code crashes. You'll need to offset the drawing by the scroll amount. That's easy to do:

private void panel1_Paint(object sender, PaintEventArgs e) {
  e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
  // etc
  //...
}

这篇关于画上面板允许自动滚屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆