How to add "buttons" to Tabbedpanel

3

I'm involved in a personal project where I want to work out a calculator with some items that are inserted in arrays. I chose a class called "calc.cs" to construct a method with a code similar to this

  public void AddDrinkstoTabbedpanel()
        {

              List<string> drinks = new List<string>();//New list empty
              food foo = new food();//Call food to get drinks
              string [] product = foo.name;//string product [] = food.name (drinks)
              foreach (string value in product)//(string value in product)//for any "value" in product 
              {
                  drinks.Add(value);//Add these value to list

                  Button bt = new Button();//new button(s)
                  bt.Text = value.ToString();//Add text to button 
              }

        }

I tried to get the "items" that are stored in "arrays" by entering: Messagebox.Show(value); and in fact I get all the items I want.

However, the solution does not create the button for each item, why?

Where I failed, what's wrong?

    
asked by anonymous 24.02.2014 / 12:24

1 answer

2

To add a button to some component, you can use the Add .

In case to add it to a TabPage of a TabControl, you could pass the first as a parameter to your method:

public void AddDrinkstoTabbedpanel(TabPage tp)
        {
            List<string> drinks = new List<string>();
            food foo = new food();
            string[] product = foo.name;
            foreach (string value in product)
            {
                drinks.Add(value);

                Button bt = new Button();
                bt.Text = value.ToString();
                tp.Controls.Add(bt); //Adiciona o botão a TabPage
            }
        }
    
24.02.2014 / 13:18