我把代码附在下面    请高手解救啊
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 电池检测软件
{
    public partial class frmhuitu : Form
    {
        public frmhuitu()
        {
            InitializeComponent();
        }
             #region   //画出X轴与Y轴
        private void DrawXY()
        {
            int MaxX=200;
            int MaxY=200;
            Graphics g = this.ImagePanel.CreateGraphics();
            MaxX = System.Convert.ToInt32(MaxX);
            MaxY = System.Convert.ToInt32(MaxY);
            Point px1 = new Point(0, MaxY/2);
            Point px2 = new Point(MaxX, MaxY/2);
            g.DrawLine(new Pen(Brushes.Black, 1), px1, px2);
            Point py1 = new Point(0, MaxY);
            Point py2 = new Point(0, 0);
            g.DrawLine(new Pen(Brushes.Black, 1), py1, py2);
        }
        #endregion        #region   画出X轴上的分值线
        private void DrawXLine()
        {
            int MaxX=200;
            int MaxY=200;
            Graphics g = this.ImagePanel.CreateGraphics();
            MaxX = System.Convert.ToInt32(MaxX);
            MaxY = System.Convert.ToInt32(MaxY);
            for (int i = 20; i > 0; i--)
            {
                Point px1 = new Point(0, MaxY -10*i);
                Point px2 = new Point(MaxX, MaxY - 10 * i);
                g.DrawLine(new Pen(Brushes.Black, 1), px1, px2);            }        }
        #endregion        #region   画出Y轴上的分值线
        private void DrawYLine()
        {
            int MaxX=200;
            int MaxY=200;
            Graphics g = this.ImagePanel.CreateGraphics();
            MaxX = System.Convert.ToInt32(MaxX);
            MaxY = System.Convert.ToInt32(MaxY);
            for (int i = 1; i<=20; i++)
            {
                Point py1 = new Point(MaxX - 10 * i, MaxY - 200);
                Point py2 = new Point(MaxX - 10 * i, MaxY);
                g.DrawLine(new Pen(Brushes.Black, 1), py1, py2);
            }
        }
        #endregion
         #region   画出每个变量的趋势线
        private void DrawData(string ProName, string[] String1, Pen pen)
        {
            Graphics g = this.ImagePanel.CreateGraphics();
            int Tim = frmlishishuju.strTime.Count();
            string[] Times = new string[Tim];
            for (int i=0;i<Tim;i++)
            {
                Times[i]=frmlishishuju.strTime[i].ToString();
            }
            //----对数据进行画线 
            for (int i = 0; i <Tim-1; i++)
            {
                g.DrawLine(pen, System.Convert.ToSingle(Times[i]), System.Convert.ToSingle(String1[i]),
                    System.Convert.ToSingle(Times[i + 1]), System.Convert.ToSingle(String1[i + 1]));
            }
            //--------------------------------------------------------------   
            //----------------该句用来注明参数名称----------------   
            g.DrawString(ProName, new Font("宋体", 12f), pen.Brush, new PointF(
              System.Convert.ToSingle(Times[Tim-1]), System.Convert.ToSingle(String1[Tim-1])));
            //-------------------------------------------------------------   
        }
        #endregion
        private void btnguanbi_Click(object sender, EventArgs e)
        {
            this.Close();
        }        private void frmhuitu_Load(object sender, EventArgs e)
        {
            string ProName = "电压";
            int sum = frmlishishuju.strVoltage.Count();
            string[] String1 = new string[sum];
            for (int i = 0; i < sum; i++)
            {
                String1[i] = frmlishishuju.strVoltage[i].ToString();
            }
            Pen pen = new Pen(Color.Red, 1);
            this.ImagePanel.Refresh();
            DrawXY();   //绘XY轴   
            DrawXLine();//绘X轴分值线   
            DrawYLine();//绘Y轴分值线   
            this.DrawData(ProName, String1, pen);
                    }
    }
}

解决方案 »

  1.   

    对象g不能这样创建,窗体刷新后绘制就没有了。             Bitmap bitmap;
    private void frmhuitu_Load(object sender, EventArgs e)
    {
    bitmap = new Bitmap(ImagePanel.Width, ImagePanel.Height);
    Graphics g = Graphics.FromImage(bitmap);//在位图上绘制 string ProName = "电压";
    int sum = frmlishishuju.strVoltage.Count();
    string[] String1 = new string[sum];
    for (int i = 0; i < sum; i++)
    {
    String1[i] = frmlishishuju.strVoltage[i].ToString();
    }
    Pen pen = new Pen(Color.Red, 1);
    DrawXY(g); //传递绘图对象
    DrawXLine(g); 
    DrawYLine(g); 
    this.DrawData(g,ProName, String1, pen);
    ImagePanel.BackgroundImage=bitmap;
     
    }
      

  2.   

    DrawXY、DrawXLine等方法要改。
    Graphics g = this.ImagePanel.CreateGraphics();
    这句要删除
      

  3.   

    DrawXY、DrawXLine等方法都改了
    Graphics g = this.ImagePanel.CreateGraphics();也都换成你说的
     bitmap = new Bitmap(ImagePanel.Width, ImagePanel.Height);
                Graphics g = Graphics.FromImage(bitmap);//在位图上绘制