求C#scrollbar 的scroll事件和valuechanged事件的区别。比如以下运行结果,(visual studio2008)
代码:- 自定义方法:public void draw(float x1, float y1, float x2, float y2, float x3, float y3, int n)
- {
- Pen p=new Pen(Color.Black);
- g.DrawLine(p, x1, y1, x2, y2);
- g.DrawLine(p,x2,y2,x3,y3);
- g.DrawLine(p,x1,y1,x3,y3);
- if (n > 2)
- {
- draw(x2, y1, (x2 - (x1 - x2) / 2), y1 + (y2 - y1) / 2, (x1 + x2) / 2, y1 + (y2 - y1) / 2,n-1);
- draw(x3, y1, (x1 + x3) / 2, y1 + (y2 - y1) / 2, x3 + (x3 - x1) / 2, y1 + (y2 - y1) / 2,n-1);
- draw(x1,y3,(x1+x2)/2,y3+(y3-y1)/2,(x1+x3)/2,y3+(y3-y1)/2,n-1);
- }
- p.Dispose();
- }
-
- 事件代码:g = pictureBox1.CreateGraphics();
- g.Clear(this.BackColor);
- int n = hScrollBar1.Value;
- label1.Text = n.ToString();
- if (n == 0)
- { ;}
- else if (n == 1)
- { g.DrawLine(Pens.Black, a, b); g.DrawLine(Pens.Black, a, c); g.DrawLine(Pens.Black, b, c); }
- else
- {
- g.DrawLine(Pens.Black, a, b); g.DrawLine(Pens.Black, a, c); g.DrawLine(Pens.Black, b, c);
- draw((b.X + a.X) / 2, 10, (c.X + a.X) / 2, (a.Y + c.Y) / 2, (b.X + c.X) / 2, (a.Y + c.Y) / 2, n);
- }
复制代码 事件代码用scroll事件运行,每次滑动会把上一次的先画一遍,再画这一次的;可是用valuechanged事件运行就不会,何解? |
|