日期:2014-05-18  浏览次数:21192 次

怎样使画在控件上的图片不被刷新掉
怎样使画在控件上的图片不被刷新掉

------解决方案--------------------
定义一个Image:
 Image i;
让控件的control.BackgroundImage=i;
然后在该image上画.
Graphics g = Graphics.FromImage(i);
g.FillRectangle(Brushes.Red, new Rectangle(10, 10, 40, 50));
control.Refresh();

------解决方案--------------------
重载OnPaint() , 
protected override void OnPaint( PaintEventArgs e )

{
base.OnPaint(e);

Graphics dc = e.Graphics;

Pen bluePen = new Pen(Color.Blue, 3);

dc.DrawRectangle(bluePen, 0,0,50,50);

Pen redPen = new Pen(Color.Red, 2);

dc.DrawEllipse(redPen, 0, 50, 80, 60);

}
或者直接令写函数,注册到控件的paint上比如 this.Paint += new System.Windows.Forms.PaintEventHandler(this.luanPaint);其中luanPaint为你自己写的函数.