用GDI+实现地图,在pictureBox1中绘制地图,代码如下:
public void Map()//绘制地图的函数
{
Graphics grapfics = pictureBox1.CreateGraphics();
grapfics.Clear(Color.White);//清空并重置背景色
Pen blackPen = new Pen(Color.Blue, 1);//边框颜色及线条粗细
SolidBrush brush = new SolidBrush(Color.Black);//填充颜色
for (i = 0; i < 300; i += 20)//点数及基本地图大小
{
for (j = 0; j <= 300; j += 20)
{
Rectangle point = new Rectangle(i, j, 20, 20);//定位点的
grapfics.FillRectangle(brush, i, j, 20, 20);
grapfics.DrawRectangle(blackPen, point);//
}
}
}