问题描述
publicForm1(){InitializeComponent();}Pointpoint1=newPoint(20,20);privatevoidForm1_Load(objectsender,EventArgse){}privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=this.CreateGraphics();Rectanglerectangle=newRectangle(point1,newSize(30,30));Penpen1=newPen(Color.Red);g.DrawEllipse(pen1,rectangle);}privatevoidbutton1_Click(objectsender,EventArgse){point1=newPoint(20,40);Invalidate();//调用Invalidate方法,实现重绘}上面是一个简单的调用Invalidate方法实现重绘的代码,我想问:上面例子是form1_paint事件,如果想实现panel1_Paint事件,该怎么做呢?如果Form1中有多个paint事件,Invalidate是调用的哪个paint事件呢?
解决方案
解决方案二:
如果Form1中有多个paint事件,Invalidate是调用的哪个paint事件呢?打开form.design.cs文件里面有类似this.Paint+=newEventHandler(Form1_Paint);这样的代码。调用的就是这个里面指定的方法。至于如何编写Panel的Paint,原理是一样的。
解决方案三:
我是说,比如:publicForm1(){InitializeComponent();}privatevoidpanel1_Paint(objectsender,PaintEventArgse){}privatevoidbutton9_Click(objectsender,EventArgse){......Invalidate();//这里怎么不能调用panel1_Paint事件呢?}如何调用panel1_Paint事件
解决方案四:
等待答案啊
解决方案五:
panel1.Invalidate()
解决方案六:
引用2楼sdfsdf43的回复:
我是说,比如:publicForm1(){InitializeComponent();}privatevoidpanel1_Paint(objectsender,PaintEventArgse){}privatevoidbutton9_Click(objectsender,EventArgse){......……
这里调用的是this.Invalidate();也就是form的Invalidate
解决方案七:
引用2楼sdfsdf43的回复:
我是说,比如:publicForm1(){InitializeComponent();}privatevoidpanel1_Paint(objectsender,PaintEventArgse){}privatevoidbutton9_Click(objectsender,EventArgse)……
这里调用的是当前窗体的Invalidate。就是this.Invalidate想调用panel的试试panel1.Invalidate()
解决方案八:
谁的Paint,就谁的Invalidate,panel1.Invalidate