How can I make a large grid of buttons (24x20 or similar) in vb.net using winforms?

后端 未结 2 1639
执念已碎
执念已碎 2021-01-27 09:19

I\'m making a seat booking system in vb.net (WinForms) and I need the user to be able to select the seat they wish to use and for it to change colour (so they can tell that it s

2条回答
  •  無奈伤痛
    2021-01-27 09:50

    Try this:

     private void Form1_Load(object sender, EventArgs e)
            {
                int index;
                Button[] b=new Button[500];
                for(int i=0;i<24;i++)
                for(int j=0;j<20;j++)
                {
                    index = (20 * i) + j;
                    b[index]=new Button();
                    b[index].Text=index.ToString();
                    b[index].Location=new Point(j*80,i*30);
                    panel1.Controls.Add(b[index]);
                    b[index].Click += new EventHandler(ButtonLeft_Click);    
                 }
    
                }
    
            private void ButtonLeft_Click(object sender, EventArgs e)
            {
                Button b = (Button)sender;
                if (b.BackColor == Color.Black)
                    b.BackColor = Color.White;
                else
                    b.BackColor = Color.Black;
    
                  //DB Commands here    
            }
    

提交回复
热议问题