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

Finding name and type

P: n/a
Finding name and type

In the activate procedure of a form I want to write to the debug window,
name and type of all controls at that actual form. Is there a smart way to
do that?

Allso for the entire application I want to print the name of all forms to
the debug window.

TIRislaa
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

This should help you for the controls,but it isn' t a complete answer
because if you've got a panel or a groupbox you'll have to check if a
control is a panel or groupbox and then also print all controls contained in
the panel or groupbox. But this should get you started

Dim ctr As Control
For Each ctr In Me.Controls
Debug.WriteLine(ctr.Name)
Next

hth Peter

"Tor Inge Rislaa" <no*************@rislaa.no> wrote in message
news:_P****************@news4.e.nsc.no...
Finding name and type

In the activate procedure of a form I want to write to the debug window,
name and type of all controls at that actual form. Is there a smart way to
do that?

Allso for the entire application I want to print the name of all forms to
the debug window.

TIRislaa

Nov 21 '05 #2

P: n/a
Hi Tor,

To do so, you can write the following code,

Dim c As Control
For Each c In Me.Controls
Diagnostics.Debug.WriteLine(c.GetType().ToString)
Next

For more information on how to use Controls Collection, you can refer to the
following link

[Controls Collection Changes in Visual Basic .NET]
http://msdn.microsoft.com/library/de...albasicnet.asp

HTH

Mona
"Tor Inge Rislaa" <no*************@rislaa.no> wrote in message
news:_P****************@news4.e.nsc.no...
Finding name and type

In the activate procedure of a form I want to write to the debug window,
name and type of all controls at that actual form. Is there a smart way to
do that?

Allso for the entire application I want to print the name of all forms to
the debug window.

TIRislaa


Nov 21 '05 #3

P: n/a
Recursion solves the problem with printing controls that contain other
controls (such as Form, Panel or GroupBox). Because all controls--including
Forms--derive from Control, which has a Controls collection, it's simple.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
showControlTypeName(Me, 0)
End Sub

Private Sub showControlTypeName(ByVal ctl As Control, ByVal indent As
Integer)
Debug.WriteLine(Space(indent * 3) & ctl.Name & ", " &
ctl.GetType().Name)
For Each child As Control In ctl.Controls
showControlTypeName(child, indent + 1)
Next
End Sub

"Tor Inge Rislaa" <no*************@rislaa.no> wrote in message
news:_P****************@news4.e.nsc.no...
Finding name and type

In the activate procedure of a form I want to write to the debug window,
name and type of all controls at that actual form. Is there a smart way to
do that?

Allso for the entire application I want to print the name of all forms to
the debug window.

TIRislaa

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.