我现在做了一个18*18的正方形。我想用黑色填充正方形的第一个边界,就像图片中一样,
我该怎么办?
public partial class Form1 : Form
{
private int XTILES = 25;
private int YTILES = 25;
private int TILELOCATION = 20;
Graphics g;
Pen pen;
public Form1()
{
InitializeComponent();
pen = new Pen(Color.Black);
}
private void DrawBoard()
{
g = panel.CreateGraphics();
for(int i = 0; i < 19; i++)
{
g.DrawLine(pen, new Point(TILELOCATION + i * XTILES, TILELOCATION),
new Point(TILELOCATION + i * XTILES, TILELOCATION + 18 * XTILES));
g.DrawLine(pen, new Point(TILELOCATION, TILELOCATION + i * YTILES),
new Point(TILELOCATION + 18 * YTILES, TILELOCATION + i * YTILES));
}
}
private void panel_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
DrawBoard();
}
}
1条答案
按热度按时间ev7lccsx1#
方法有很多,下面是其中之一:使用FillRect分别绘制上、左、右和下边缘。
[添加-参见备注]: