c# 绘制网格

    Bitmap bmp;
        private void label1_Click(object sender, EventArgs e)
        {
            bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            this.pictureBox1.Image = bmp;
            Graphics g = Graphics.FromImage(bmp);
            sss(g);
        }
       //绘制网络
        public void sss(Graphics g){

            try
            {
                Pen myPen = Pens.Thistle;
                //垂直
                for (int i = 0; i < this.pictureBox1.Width; i++)
                {
                    //g.GetHdc();
                    g.DrawLine(myPen, new Point(i, 0), new Point(i, this.pictureBox1.Height));
                    i += 60;
                }
                //水平
                for (int j = 0; j < this.pictureBox1.Height; j++)
                {
                    g.DrawLine(myPen, new Point(0, j), new Point(this.pictureBox1.Width, j));
                    j += (this.pictureBox1.Height - 6) / 10;
                }
            }
            catch (Exception x)
            {


            }
       
        }

测试正确,可以画出网格,今天改代码的时候 垂直网络一直出不来 ,感觉很失败。有点灰心了,,,

你可能感兴趣的:(C#,网格)