473,407 Members | 2,598 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,407 software developers and data experts.

All Forms And Controls In An Application

At run-time is there a way to get the names of all form classes and the
controls defined within each without instantiating the form classes?
I'm not doing any dynamic adding to the controls so the set of controls
added at design-time would be what I'm looking for.

If it can't be accomplished without instantiating then I do have code
to get all the controls from a given form class by instantiating that
form. What I'm having trouble with is getting all the form classes
within an application and instantiating each of those. The following
snippet will display the class name of each class defined in the
application, however I'm having trouble picking out only those that
inherit form and how to instantiate those that do.

Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
For Each oType As Type In thisExe.GetTypes
MsgBox(oType.ToString)
Next

Thanks,
Bill

Dec 14 '05 #1
3 1035
Well, I answered one part. The following snippet shows the names of
forms classes:

Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
For Each oType As Type In thisExe.GetTypes
If oType.BaseType.ToString _
= "System.Windows.Forms.Form" Then
MsgBox(oType.ToString)
End If
Next

Now I'll see if I can instantiate them.

Dec 15 '05 #2
Now I have it solved with instantiation (yes, I tried for a long while
before I sent the original request but things seem to have fallen
together). The following snippet gives all the controls in all the
form classes:

Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
For Each oType As Type In thisExe.GetTypes
If oType.BaseType.ToString _
= "System.Windows.Forms.Form" Then
MsgBox(Me.GetControlHierarchy( _
CType(Activator.CreateInstance(oType), Form)))
End If
Next

Private Function GetControlHierarchy( _
ByRef roForm As Form) As String
If roForm Is Nothing Then
Return "Form not instantiated."
End If

Dim sReturn As String = "FORM: " & roForm.ToString

For Each oControl As Control In roForm.Controls
sReturn &= vbNewLine & GetControlHierarchy(oControl, 1)
Next

Return sReturn
End Function

Private Function GetControlHierarchy( _
ByRef roControl As Control, _
ByVal riLevel As Integer) As String
If roControl Is Nothing Then
Return ""
End If

Dim sReturn As String
For iLevel As Integer = 1 To riLevel
sReturn &= "----> "
Next
sReturn &= "CONTROL: " & roControl.ToString

For Each oControl As Control In roControl.Controls
sReturn &= vbNewLine & _
GetControlHierarchy(oControl, riLevel + 1)
Next

Return sReturn
End Function

Dec 15 '05 #3
I'd still really like to know how to do this without instantiating the
forms. If anyone out there knows how to do this it would be great.
There's gotta be a way.

Dec 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
4
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
22
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one...
4
by: Pini | last post by:
Hi all, I have a massive windows application that refernces a lot of assemblies and doing a lot of DAL anf IO operations. I want to expose this application to the interner so that a user can...
10
by: RobinS | last post by:
Hello to all, and happy new year! I have this application that someone wrote that I'm sort of checking out. The forms look fine in design mode, but when I run the application, it crops off the...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
0
by: vimalkanth | last post by:
Hi, We have a Delphi 5 Windows application which is built as a Client- Designer-Server application with http-based data exchange between Client/Designer and Server. Client application is...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.