windows forms controls and selecting current form

J

jamie

This is less of a syntax and more of a design question I think. I've been
developing an application that runs on a pocketPC device. The application
has a menu and multiple "screens" to it. Basically what I've been doing is
for each screen developing a new windows form for that screen and doing
everything required there. The program opens each new form with
"classname.Show()" from each form as they are needed/selected. The user
then moves back to the previous form by pressing ESC which calls
this.Close() on the form putting you back to the previous form. This
worked well to begin with but I'm now starting to get chains of forms 7
deep. I'm having trouble now that I'd like to be able to jump to any of
the open forms. If I'm in form #7 and I want to go to form #6 thats easy
with the close but what if I want to go from form #7 to form #4? I'm also
worried that this is starting to eat up a lot of resources with forums
sitting there idling while the user is way down in the program.

Does anyone have recommendations on how to get a list of all forms that are
open so that I can call focus on the ones that I want when I want? Any
other recommendations on how to make all of this work?
 
D

Dinesh Bajaj

Hi,

Check this solution (in VB.Net):

'Declare and instantiate this variable globally. We do this in a module
in VB.
'A collection to hold the references to all open forms.
Public g_Forms As New
System.Collections.Specialized.HybridDictionary(7)

'In a form's Load event-handler
'Use the form's class name as the key. Add the instance to the
collection.
g_Forms.Add(Me.GetType.Name, Me)

'In a form's Closing event-handler
'Remove the instance from the collection.
g_Forms.Remove(Me.GetType.Name)

'To display a form
CType(g_Forms.Item("FormClassName"), Form).Show()

To save on the resources, consider using panels in a form to simulate
multiple forms. I frequently do this to avoid creating a new form for a
trivial task.

Also, check out this link to a related MSDN article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfuiframework.asp
 

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

Top