问题描述
大家看这个程序://20071023usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;classDrawDemo:Form{publicDrawDemo(){Text="DrawDemo";StartPosition=FormStartPosition.CenterScreen;}protectedoverridevoidOnPaint(PaintEventArgse){Graphicsg=e.Graphics;<fontcolor=red>intGleft=100;</font><fontcolor=red>intGheight=10;</font>g.DrawLine(newPen(Color.Red,2),<fontcolor=red>Gleft;</font>,<fontcolor=red>Gheight;</font>,100,2);}staticvoidMain(string[]args){Application.Run(newDrawDemo());}}我想为<fontcolor=red>Gleft</font>和<fontcolor=red>Gheight</font>重新赋值,并且清除过去的图像,怎么做?
解决方案
解决方案二:
Gleft和Gheight定义成全局变量,修改值以后,调用this.Refresh会重新触发onpaint事件
时间: 2024-10-30 11:01:17