我正在使用 C# 构建座位预留软件,我很困惑如何立即绘制大量座位。我正在尝试三种方式,即..
- 使用用户控件

    public void DrawUsercontrol(int x, int y)
    {
        int space = 4;
        int SeatLimit = 165;
        int RowSeatLimit = 15;
        for (var i = 1; i < SeatLimit; i++)
        {
            UserControl1 ctrl = new UserControl1();
            ctrl.Size = new System.Drawing.Size(25, 25);
            ctrl.Location = new Point(x + space, y);
            if (i % RowSeatLimit == 0)
            {
                x = 1;
                y = y + 25 + space;
            }
            x = x + 25 + space;
            ctrl.label1.Text = i.ToString();
            ctrl.label1.Click += new EventHandler(label1_Click);
            panel1.Controls.Add(ctrl);
        }
    }
- 使用“面板”控件 - public void DrawingPanel(int x, int y) { Panel myPanel = new Panel(); int width = 16; int height = 16; myPanel.Size = new Size(width, height); myPanel.BackColor = Color.White; myPanel.Location = new Point(x, y); Label mylabel = new Label(); mylabel.Text = "4"; myPanel.Controls.Add(mylabel); myPanel.BackColor = Color.YellowGreen; // this.Controls.Add(myPanel); panel1.Controls.Add(myPanel); }
- 使用图形和绘制矩形 - public void DrawingSquares(int x, int y) { SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red); Graphics graphicsObj; graphicsObj = this.panel1.CreateGraphics(); Rectangle myRectangle = new Rectangle(x, y, 30, 30); graphicsObj.FillRectangle(myBrush, myRectangle); graphicsObj.Dispose(); }
我参考第一个选项,但它太慢了。我该如何决定?