欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C# 用GDI绘制二维网格坐标

程序员文章站 2024-01-24 15:45:16
...

效果图:
C# 用GDI绘制二维网格坐标
代码如下:
//绘制二维坐标
private void button_DrawCoordinate_Click(object sender, EventArgs e) //绘制坐标系
{
Graphics g = CreateGraphics();
Pen m_pen = new Pen(Color.Black,2);
Pen m_pen1 = new Pen(Color.FromArgb(101, 189, 101), 1);
Brush m_brush = new SolidBrush(Color.FromArgb(51,119,51));
int x = 30;
int y = 30;
g.DrawRectangle(m_pen,x,y,700,300);
g.FillRectangle(m_brush, x+1,y+1,698,298);
for (int i = 0; i < 6; i++)
{
string draw_str = string.Format("{0}", 6000 - 1000 * i); //画刻度
g.DrawString(draw_str, this.Font, Brushes.Black, new Point(2, y-5));
y += 50;
g.DrawLine(m_pen1,30,y,730,y); //画横线

        }
        for (int i = 0; i < 14; i++)       //绘制竖线和刻标
        {
            string draw_str = string.Format("{0}", 1000 * i);
            g.DrawString(draw_str, this.Font, Brushes.Black, new Point(x-13, 332));  
            x += 50;
            g.DrawLine(m_pen1, x, 30, x, 330);
            g.DrawString("14000", this.Font, Brushes.Black, new Point(730-13, 332)); //绘制最终的刻度
        }

    }

小白一枚,各位大神有没有更好的方法,还请不吝赐教,多多讨论交流

相关标签: c#