Iawfy_
2020-09-03 08:58
采纳率: 60%
浏览 241

C#窗体的paint事件运行后没结果

直接在窗体的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);
        }
    }

运行后就只跳出按任意键继续的窗口。

1条回答 默认 最新

相关推荐 更多相似问题