使用GDI+绘制一条线段,当我把窗体最小化以后,然后再还原窗体,那个线段怎么就不见了,是怎么回事

解决方案 »

  1.   

    将绘制一条线的代码写在onpaint里
      

  2.   

    因为你是直接在窗体上绘制的也就是用createGraphics,当最小化后在最大化时,窗体会刷新一下,这时就把你画的线刷没了;你要把绘制程序写到窗体的OnPaint事件里,这样才会持久。
      

  3.   

    好像onpaint是一个方法吧,只看到paint事件,能具体说说onpaint如何用吗?
      

  4.   

    加入你的窗体为Form1,那么,在窗体的event里找到OnPaint事件,双击进入该事件,在该事件里写你的画线程序就OK了
      

  5.   

    就是Paint事件,你把画图程序放在里面就行了
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication20
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics();
                g.DrawLine(new Pen(Color.Red, 2), new Point(10, 10), new Point(100, 100));
                g.Dispose();
            }
        }
    }
      

  7.   

    你好 我想问个比较低级的问题。但是我真的不懂 
    你用g.DrawLine(new Pen(Color.Red, 2), new Point(10, 10), new Point(100, 100)); g.DrawLine(new Pen(Color.Red, 2), 10, 10,100, 100)); 也可以吧 你那样的话 对程序来说效率会更快么? 我是菜鸟。最近刚刚开始研究DGI+绘图和图像处理
      

  8.   

    因为你只是画在表面上,需要在OnPaint里重画