Finding name and type

  • Thread starter Thread starter Tor Inge Rislaa
  • Start date Start date
T

Tor Inge Rislaa

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top