473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Can I create a handler against a windows contol class?

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
3 1056
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
* "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with...
7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
15
by: Brian Rogers | last post by:
Hello everyone, I apologize for the cross and re-post, but I am still searching for an answer. Why can C++ can create this object, but C# can't? I am trying to create an instance of the...
10
by: SunshineGirl | last post by:
In my code, class A instanciates classes B and C. I would like class B to connect an event handler to a method in class A, and for class C to disconnect that event handler. I think I've done...
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
2
by: forest demon | last post by:
I need to be able to create an appender to direct output to a MessageBox. The API does not have a MessageBox appender like nLog does. What would be the easiest way to do this. The examples...
18
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code using classes how can we 'hide' the fact that it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.