C# 2.0 在Picturebox绘制 网格线

来源:互联网 发布:知商金融李文超 编辑:程序博客网 时间:2024/06/06 07:20

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Roading001
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

 

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            drawGrids(e);
        }

 

        private void drawGrids(PaintEventArgs e)
        {           
            Graphics g = e.Graphics;
            Pen myPen = Pens.Blue;
            for (int i = 0; i < ClientRectangle.Width; i++)
            {
                g.DrawLine(myPen, new Point(i, 0), new Point(i, ClientRectangle.Bottom));
                i += 10;
            }

            for (int j = 0; j < ClientRectangle.Height; j++)
            {
                g.DrawLine(myPen, new Point(0, j), new Point(ClientRectangle.Right, j));
                j += 10;
            }
        }

 

    }
}

原创粉丝点击