Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scanning all Controls in a form
Message
From
29/01/2007 01:01:57
 
 
To
25/01/2007 01:55:14
Rahul Murarka
Sys-Con Engineering
Kolkata, India
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01189038
Message ID:
01189964
Views:
17
For VB6, here are a couple of samples

For just one type of control:
Text1.Tag = Now
Text2.Tag = Now

Dim myControl As TextBox
For Each myControl In Me.Controls
   myControl.Text = myControl.Tag
 Next myControl
For ALL controls: (Use TypeOf to distinguish specific control-type)
Text1.Tag = Now
Text2.Tag = Now

Dim myControl As Control
For Each myControl In Me.Controls
   If TypeOf myControl Is TextBox Then myControl.Text = myControl.Tag
 Next myControl
This won't work correctly for VB.NET, though, since they enforce Control-ownership differently: child-controls won't be included in the collection

For VB.NET 2002, I use this procedure to set the ToolTip of all applicable controls to display the maximum length by calling the procedure and passing the form (yes, the form!) as the first parameter and a ToolTip object as the second; just remove the second parameter to fit your needs
   Public Sub SetFormControlsTooltips(ByRef myControlsCollection As Control, ByVal myTooltip As ToolTip)
      Dim myControl As Control
      For Each myControl In myControlsCollection.Controls
         If TypeOf myControl Is TextBox Then
            Dim myTextBox As TextBox = DirectCast(myControl, TextBox)
            If myTextBox.MaxLength > 0 Then myTooltip.SetToolTip(myControl, "Max Length: " & myTextBox.MaxLength & " char(s)")
         End If

         If TypeOf myControl Is GroupBox Or TypeOf myControl Is Panel Then
            Call SetFormControlsTooltips(myControl, myTooltip)
         End If
      Next
   End Sub
usage:
Dim ttpToolTip As New ToolTip()
Call SetFormControlsTooltips(Me, ttpToolTip)

Notice the last If-Statement, which calls the same procedure but with a different object this time, which is a containter object


Hope this helps!
evolve or die.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform