it gives "An unhandled exception of type 'System.NullReferenceException' occurred in xxxx.exe" error with Additional information: Object reference not set to an instance of an object
what is the problem i didnt understand :S
(i am using vb 2005)
Last edited by matatu; November 25th, 2008 at 05:00 AM.
Reason: version of my visual basic compiler
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
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.
Last edited by matatu; November 25th, 2008 at 05:56 AM.
Reason: improvement
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...
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
Bookmarks