画图的Graphics可能选的不合适。应该使用它的参数里的Graphics(e.Graphics);

解决方案 »

  1.   

    private void CreateForm()
            { 
                //创建画板
                Graphics g = lblForm.CreateGraphics();
                //this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);            try
                {
                    g.Clear(Color.White);
                    Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
                    Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
                    System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, lblForm.Width, lblForm.Height), Color.Blue, Color.Blue,1.2f,true);
                    //填充画板背景色
                    g.FillRectangle(Brushes.White, 0, 0, lblForm.Width, lblForm.Height);
                    //画图片边框线
                    g.DrawRectangle(new Pen(Color.Blue), 0, 0, lblForm.Width - 1, lblForm.Height - 1);                Pen mypen = new Pen(brush, 1);
                    Pen mypen2 = new Pen(Color.Red, 2);                //绘制纵向线条
                    int x = 20;
                    for (int i = 0; i < 12; i++)
                    {
                        g.DrawLine(mypen, x, 30, x, 200);
                        x += 20;
                    }
                }
                finally
                {
                    g.Dispose();
                }
      

  2.   

    lblForm是什么?是Label?你为什么不添加Label的Paint事件呢?把画的代码放到Paint里,不要CreateGraphics。