我在程序的from1_Paint事件中编写了以下代码:
其中graphics_array是一个已赋值的二维结构体数组, width也已赋值 但运行后没有任何反应这是怎么回事???          
Graphics mygraphics =this.CreateGraphics();
            Pen mypen = new Pen(Color.Black);         
            for (i = 0; i < len; i++)
            {
                for (j = 0; j < len; j++)
                {
   mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width);
                }
            }

解决方案 »

  1.   

    是不是没有放在paint事件里面 或 重画 
    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);
    }
    ,直接写LOAD事件里面不会显示的
      

  2.   

    查一下mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width); 
                    } 
    有没有执行,或画到了该form的外面.
    另:
     Graphics mygraphics =this.CreateGraphics(); 
    可用
      private void Form1_Paint(object sender, PaintEventArgs e)
            {
                 Graphics mygraphics = e.Graphics;
                   ............
            }
      

  3.   

     imgPic = new Bitmap(708, 440);
                pictureBox1.Image = imgPic;
                Graphics grp = Graphics.FromImage(imgPic);
                grp.SmoothingMode = SmoothingMode.AntiAlias;
                pictureBox1.Refresh();
                Pen mypen = new Pen(Color.Black);
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        grp.DrawRectangle(mypen, i, j, i+i,j*j);
                    }
                }
    放个 pictureBox1试一试
    记得给分哦
      

  4.   

    Graphics mygraphics =  e.Graphics; 
                Pen mypen = new Pen(Color.Black);        
                for (i = 0; i < len; i++) 
                { 
                    for (j = 0; j < len; j++) 
                    { 
      mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width); 
                    } 
                }