By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Can I create a handler against a windows contol class?

P: n/a
Hi guys,

I'm sure I'm just not thinking far enough outside the box - am a VB6er
trying to enter this .NET OOP world.....

This is what I have...

For Each c As Control In Me.Controls
If c.GetType.ToString = "System.Windows.Forms.TextBox" Then
If c.Enabled = False Then
c.BackColor = System.Drawing.Color.White
End If
ElseIf c.GetType.ToString = "System.Windows.Forms.GroupBox" Then
For Each gc As Control In c.Controls
If gc.GetType.ToString = "System.Windows.Forms.TextBox" Then
If gc.Enabled = False Then
gc.BackColor = System.Drawing.Color.White
End If
End If
Next
End If
Next

As you an see, I am trying to change the colors for any textbox (inclouding
those sittiing in other controls) that is disabled - not very OO - in VB6 I
would probably have created a control array and done something like 'For
each Textbox as tb in Me.txtarray'....

However, I can see some really good possibilities in here, in that true OO
woild be to do this upon a event - such as painting/disabling the control.

Is there a more graceful way of doing this? Maybe in a handler?

Any ideas would be appreciated.

Thanks,
Graham
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Graham,

Setting all textboxes.text to space on a form and all controlboxes index
to -1

It is not important where they are,
Watch the start with doclean(me) that is the top of the form.

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doclean(Me)
End Sub
Private Sub doclean(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
If TypeOf ctr Is TextBox Then
ctr.Text = ""
ElseIf TypeOf ctr Is ComboBox Then
DirectCast(ctr, ComboBox).SelectedIndex = -1
End If
doclean(ctr)
Next
End Sub
///
Nov 20 '05 #2

P: n/a
* "Graham Blandford" <gr**************@sympatico.ca> scripsit:
I'm sure I'm just not thinking far enough outside the box - am a VB6er
trying to enter this .NET OOP world.....

This is what I have...

For Each c As Control In Me.Controls
If c.GetType.ToString = "System.Windows.Forms.TextBox" Then
If c.Enabled = False Then
c.BackColor = System.Drawing.Color.White
End If
ElseIf c.GetType.ToString = "System.Windows.Forms.GroupBox" Then
For Each gc As Control In c.Controls
If gc.GetType.ToString = "System.Windows.Forms.TextBox" Then
\\\
If TypeOf gc Is TextBox Then
...
End If
///
If gc.Enabled = False Then
gc.BackColor = System.Drawing.Color.White
End If
End If
Next
End If
Next

As you an see, I am trying to change the colors for any textbox (inclouding
those sittiing in other controls) that is disabled - not very OO - in VB6 I
would probably have created a control array and done something like 'For
each Textbox as tb in Me.txtarray'....


Maybe this class helps you to simplify your code:

<URL:http://dotnet.mvps.org/dotnet/samples/controls/downloads/EnumerateControls.zip>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

P: n/a
Thank you Cor. Just what I needed!

Thanks again,
Graham

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Hi Graham,

Setting all textboxes.text to space on a form and all controlboxes index
to -1

It is not important where they are,
Watch the start with doclean(me) that is the top of the form.

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doclean(Me)
End Sub
Private Sub doclean(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
If TypeOf ctr Is TextBox Then
ctr.Text = ""
ElseIf TypeOf ctr Is ComboBox Then
DirectCast(ctr, ComboBox).SelectedIndex = -1
End If
doclean(ctr)
Next
End Sub
///

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.