PC Review


Reply
Thread Tools Rate Thread

Can I create a handler against a windows contol class?

 
 
Graham Blandford
Guest
Posts: n/a
 
      14th Jul 2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      14th Jul 2004
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
///


 
Reply With Quote
 
Graham Blandford
Guest
Posts: n/a
 
      14th Jul 2004
Thank you Cor. Just what I needed!

Thanks again,
Graham

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:%23x%(E-Mail Removed)...
> 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
> ///
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      14th Jul 2004
* "Graham Blandford" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to grow rich in C# the event handler of a class in an inherited class polocar Microsoft C# .NET 3 11th Dec 2006 01:51 PM
Re: Setting an Event Handler on data member of parent class in derived class Jon Skeet [C# MVP] Microsoft C# .NET 1 13th Jan 2006 07:30 AM
Connecting an event handler in one class and disconnecting it in a different class. SunshineGirl Microsoft C# .NET 11 20th Jan 2004 03:56 PM
Create new event handler or override existing handler? =?Utf-8?B?V29vbiBLaWF0?= Microsoft Dot NET Framework Forms 1 5th Jan 2004 08:08 AM
What are Handler Class files? Philip Windows XP General 0 1st Dec 2003 08:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:37 PM.