在onpaint事件里面画,画完以后如果把窗口缩小再放大就什么都没有了,怎么解决呢?

解决方案 »

  1.   

    在Paint事件里使用e.Graphics.DrawLine(...)来绘制就可以了。
      

  2.   

    当窗体主动或被动被刷新的时候执行的是Paint事件,在这个事件里有专门供画图使用的e.Graphics,所有的绘制工作可以都由它来完成,如果要达到立刻绘制出来图像,可以调用this.Invalidate()方法。
      

  3.   

    因为你改变大小一以后
    form 回调用paint事件
    所以在Paint事件里画就可以
      

  4.   

    楼上已经说的很清楚了,若是在pictureBox1上画的,只需
    pictureBox1.Image=theimage ;
      

  5.   

    OnPaint和paint方法有什么区别呢?好像都是 窗口动一下就进到函数里面去了
      

  6.   

    OnPaint是基类Control的方法,也是首选的,Paint是.net里的事件,是由OnPaint引发的,因此,使用OnPaint会好些,但是Onpaint需要手动的在代码里输入override onPaint来实现,但是Paint事件在属性窗口里打开事件页找到Paint双击就可以添加事件了。使用哪一个看你的爱好来定,我个人喜欢使用重写OnPaint方法。
      

  7.   

    窗口改变了是会调用paint重绘的...
      

  8.   

    private void Form1_Paint(object sender, PaintEventArgs e)
            {
                g = this.CreateGraphics();
                Pen pen = new Pen(Color.Black, 2);
                pen.DashStyle = DashStyle.Solid;
                //g.TranslateTransform(130, 130, MatrixOrder.Append);
                g.DrawEllipse(pen, new Rectangle(0, 0, 50, 50));
                g.DrawLine(pen, 130, 130, 180, 130);//初始线
                this.Invalidate();
            }这样窗口会不停的闪
      

  9.   

     // this.Invalidate();   这句去掉.
      

  10.   

    修改如下:private void Form1_Paint(object sender, PaintEventArgs e) 
            { 
                //g = this.CreateGraphics(); 这一句去掉
                Pen pen = new Pen(Color.Black, 2); 
                pen.DashStyle = DashStyle.Solid; 
                //g.TranslateTransform(130, 130, MatrixOrder.Append); 
                e.Graphics.DrawEllipse(pen, new Rectangle(0, 0, 50, 50)); 
                e.Graphics.DrawLine(pen, 130, 130, 180, 130);//初始线 
                //this.Invalidate(); 这一句去掉
                  pen.Dispose();
            } 
      

  11.   

    建议如下:protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    //g = this.CreateGraphics(); 这一句去掉
    using (Pen pen = new Pen(Color.Black, 2))
    {
    pen.DashStyle = DashStyle.Solid;
    //g.TranslateTransform(130, 130, MatrixOrder.Append); 
    e.Graphics.DrawEllipse(pen, new Rectangle(0, 0, 50, 50));
    e.Graphics.DrawLine(pen, 130, 130, 180, 130);//初始线 
    //this.Invalidate(); 这一句去掉
    }
    }