C# 用GDI绘制二维网格坐标
程序员文章站
2024-01-24 15:45:16
...
效果图:
代码如下:
//绘制二维坐标
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)); //绘制最终的刻度
}
}
小白一枚,各位大神有没有更好的方法,还请不吝赐教,多多讨论交流
上一篇: HDU 2457 AC 自动机 + DP
下一篇: 机器学习:特征工程