Re: Problem with TabControl
Welcome to the Forums! :wave:
You need to specify the button's container control as well.
By doing it the way you have it, it will assume that button1's container is the form. Do it like this :
Code:
Dim i As Integer = 1 'Create Variable & Set it to 1
Me.TabPage1.Controls(String.Concat("Button", i)).BackColor = System.Drawing.Color.Blue 'Set Backcolor Of Button1 To Blue
i = i + 1 'Increment Counter
Me.TabPage1.Controls(String.Concat("Button" & i)).BackColor = System.Drawing.Color.Green 'Set Background of Button2 To Green
Re: Problem with TabControl
Nice solution. It worked!
But the problem is that i have 82 buttons with 7 tabpages in one tabcontol and buttons somehow randomly distributed into tabpages :S and some buttons are directly on the forum (isnt related with any tabcontrol)
Is there any other solution for this?
There is probably 2 solutions for this problem.
One is to somehow get the button id's for every tabpages and and use above alogirthm
Second is direct acess to buttons such as buttoni.back color where i=1 to N
Maybe there is different command for the second solution.
Re: Problem with TabControl
The solution I can think of would be to use the Controls collection instead. Trust me, you'll save yourself a whole lot of trouble :)
You could loop through the form, and each tabpage and determine whether or not the "child" control is a button, then, set it's color.
Here's a bit more info on Controls Collection :
http://www.sellsbrothers.com/askthew...rolcollect.htm
http://visualbasic.about.com/od/usin...ctrlarraya.htm
http://www.eggheadcafe.com/community...the--cont.aspx
Re: Problem with TabControl
How about using something along the lines of:
Code:
For Each TabC In Me.Controls.OfType(Of TabControl)()
For Each But In TabC.Controls.OfType(Of Button)()
'Process the buttons here
Next
Next
This requires the extensions given by one of the .NET namespaces...I'll look up which one.
*EDIT*: It's needs System.Linq to be imported...