Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Each Occurance Of A Specific Control Type In A Panel 1

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
0
0
GB
I have a panel on a form containing various controls.
If I want to set all controls in the panel to a
certain set of characteristics, I can code the following:-

Dim conMyControl As Control

For Each conMyControl In MyPanel.Controls
conMyControl.ForeColor = Color.Blue
conMyControl.BackColor = Color.Wheat
Next


Is there a way I can code the same sort of logic just
for a specific control type, for example a textbox?
I've tried the following but I get a runtime compile
error even though I think I've done something like this before in the past, I can't remember how I did it.

Dim conMyControlTextBox As textBox

For Each conMyControltextBox In MyPanel.Controls
conMyControl.ForeColor = Color.Blue
conMyControl.BackColor = Color.Wheat
Next



 
Use
Code:
For Each ...
    If TypeOf conMyControl Is TextBox Then
        CType(conMyControl, TextBox).MaxLength = 20
    End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top