直接在窗体的paint事件中写的代码,运行后也没出现窗体。
public partial class Matrix : Form
{
public Matrix()
{
InitializeComponent();
}
private void Matrix_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle[] rects = new Rectangle[81];
int x = 10;
int y = 10; //开始坐标
int width = 5;
int height = 5; // 每格长及宽
int n = 0;
for (int k = 0; k < 9; k++)
{
for (int i = 0; i < 9; i++)
{
rects[n] = new Rectangle(x, y, width, height);
y = y + (i + 1) * width;
n = n + 1;
}
x = x + (k+1) * height;
y = 10;
}
g.DrawRectangles(Pens.Red, rects);
}
}
运行后就只跳出按任意键继续的窗口。