private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen blackPen = new Pen(Color.Black);
Pen whitePen = new Pen(Color.White);
int numRows = 10;
int numCols = 10;
int cellWidth = panel1.Width / numCols;
int cellHeight = panel1.Height / numRows;
for (int row = 0; row < numRows; row++)
{
for (int col = 0; col < numCols; col++)
{
if ((row + col) % 2 == 0)
{
g.DrawLine(blackPen, col * cellWidth, row * cellHeight, (col + 1) * cellWidth, row * cellHeight);
g.DrawLine(blackPen, col * cellWidth, row * cellHeight, col * cellWidth, (row + 1) * cellHeight);
}
else
{
g.DrawLine(whitePen, col * cellWidth, row * cellHeight, (col + 1) * cellWidth, row * cellHeight);
g.DrawLine(whitePen, col * cellWidth, row * cellHeight, col * cellWidth, (row + 1) * cellHeight);
}
}
}
}
winform中panel画出灰白相间的格子
最新推荐文章于 2023-11-03 11:56:00 发布