How to add "Buttons" to Tabbedpanel

Asked

Viewed 79 times

3

I am involved in a personal project in which I intend to elaborate a calculator with some items that are inserted in "arrays". I opted for a class called "Calc.Cs" to build a method with a code identical to this one

  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 inserting: Messagebox.Show(value); and in fact get all the items I want.

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

Where I failed, what’s wrong?

  • This is not a question of C#. What platform are you developing?

1 answer

2


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

In case, to add it to a Tabpage of a Tabcontrol, you could pass the first as parameter of 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
            }
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.