Seat Reservation Software: Quickly Draw Many Seats in C #

I am creating Seat reservation software using C # and I am confused how quickly I am gaining a lot of places. I try three ways that ...

  • Using Usercontrol

https://dl.dropboxusercontent.com/u/81727566/seatForm.png

    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);
        }
    }
  1. Using Panel Control

    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);
    }
    
  2. Using Graphics and Draw Rectangle

    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();
    }
    

I am sending the first option, but it is too slow. And how can I decide?

+4
source share
1 answer

Your problem is that you are adding only one control at a time. Adding a control leads to a complete update (rendering of the GDI + software is rather slow) of the parent panel (the best option) and, possibly, the entire form (worst case).

, Panel.Controls.AddRange. .

, - ( ) .

UserControl , - . , ! , , .

+4

All Articles