我是根据输入个个数来画矩阵的,比如,输入4
就画出一个指定大小的4*4的矩阵来
然后我用的是FILLRETANGLE来话填充矩阵来填充它!

解决方案 »

  1.   


                
                string str = textBox1.Text;
                n = int.Parse(str);
                Graphics g = pictureBox1.CreateGraphics();
                //Image myimage = new Bitmap(600, 800);
                pictureBox1.Image = myimage;
                g = Graphics.FromImage(myimage);
           
                Pen BluePen = new Pen(Color.Blue);
                float x =80.00F;
                float y = 50.00F;
                float d = 300.00F/n;            for (int i = 0; i <=n;i++ )
                {
                    PointF X1 = new PointF(x + i*d, y);
                    PointF X2 = new PointF(x + i*d, y + 300.00F);
                    g.DrawLine(BluePen, X1, X2);            }
                x = 80.00F;
                for (int j = 0; j <=n;j++ )
                {
                    PointF Y1 = new PointF(x, y + j*d);
                    PointF Y2 = new PointF(x + 300.00F, y + j*d);
                    g.DrawLine(BluePen, Y1, Y2);            }
                //重新初始化
                x = 80.00F;
                y = 50.00F;
    //填充
    Graphics g = pictureBox1.CreateGraphics();
                Image myimage = new Bitmap(600, 800);
                pictureBox1.Image = myimage;
                g = Graphics.FromImage(myimage);            Pen BluePen = new Pen(Color.Blue);
                SolidBrush MyBrush=new SolidBrush(Color.Red);
          
                float x =80.00F;
                float y = 50.00F;
                float d = 300.00F/n;
                if(e.X>x&&e.X<x+d&&e.Y<y+d&&e.Y>y)
               {
                   g.FillRectangle(MyBrush,x,y,d,d);
               }