Reputation: 299
I am currently trying to draw a selection of buttons for each item within a combo box below is the code i am drawing with
foreach (Object cbi in acombobox.Items)
{
Button button = new Button();
button.Location = new Point(25, 35);
button.Text = cbi.ToString();
tabbcontrol.TabPages[3].Controls.Add(button);
}
This draws the button, but it overwrites any other button, is there a way to draw the buttons at different locationson the tabcontrol?
EDIT
I didnt explain that too well how would i arrange the buttons around another button i.e. like a spider diagram so when i click the main button,the others will draw around it with lines expanding to each one?
Upvotes: 0
Views: 256
Reputation: 2953
You're drawing all your buttons at the same position. If you know how many buttons you want to add then work out the layout for them and add them at the positions you want them to be drawn.
If you're loading an unknown number of buttons then you may wish to look at the FlowLayoutPanel
control, which arranges its contents in a horizontal or vertical flow direction. That means you can add controls to it dynamically and they'll automatically be placed under each other / next to each other, rather than on top of each other.
http://msdn.microsoft.com/en-us/library/zah8ywcc.aspx
EDIT in response to the update of the original question and comments:
If you know what buttons you need at design time you could draw them and then just toggle visibility on the centeral button click. Otherwise you need to calculate their positions using some trigonometry http://en.wikipedia.org/wiki/Sine#Relation_to_the_unit_circle
Upvotes: 2
Reputation: 71945
Yes. You give them a different location. As you can see, you are currently giving all the buttons the same location, which is why they are on top of each other.
Upvotes: 3