Multiple Forms

M

Mike

I am in the process of learing .NET, particularly .NET
compact framework, so excuse me if this is obvious.... I
have a PPC application that I am developing that
currently has approximately 12 forms. I noticed that
upon deployment that navigation among/between the forms
can tend to be rather slow. My question is what is the
best way to navigate between forms in a mutliple form
application? Currently, I use the following method to
open new forms...As an example...

Dim frmMainMenu as New frmMainMenu
frmMainMenu.ShowDialog()

Is there a better way? I have seen discussion about
using panels and showing/hiding them but that seems like
it may be laborious, especially when you have up to 12
forms? Any recomendations/comments would be greatly
appreciated.

Thanks!
 
G

Girish NS

Hi,

When the number of forms increases in an CF application, it tends to become
slow. What u can do is u can have a single form with multiple panels. u can
show/hide the panels as per the menu options in the form. I have implemented
this logic in my application and the performance is good. But in our case,
it will be cumbersome for u to have 12 panels in a form. Here maybe u can
group ur forms and decide based on ur logic

This article dealing with handling multiple forms in a .NET CF application
might be of help to u.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfPPCtoCE.asp

Girish.
 
M

Mark Reddick

Another thing you could try is to "pre-load" your forms. I did this with one
of my apps and the performance was greatly improved. You end up taking a
hit, however, at the start of the app. I just show a splash screen while I
preload the forms. The way I did this was to setup a static class with some
variables for each of my forms and then set them at app start. Then, I just
use those global variables to show/hide the forms.

- Mark
 
V

Venue

In both the examples below, after clicking couple of times through Movies
and Actors. If I look at Stack Info, it shows big list of forms cached (same
form multiple times). I guess I am missing something here, won't it be good
idea to have just one instance of form and load it with new set of data
(what Mark suggested above).
 
C

Chris Tacke, eMVP

Take a look at the articles. Only 1 instance of any specific Form is
cached. There are no multiple copies.
 
V

Venue

But somehow when I run the application and click couple of times on Actor
and Movie and then go and check the running programs on the device it shows
me multiple copies of Actor/Movie forms running and I can do EndTask to each
individual form. Why is that?
 
M

Mike

Justin, thanks for your reply. I attempted to integrate
it into my project but got a "NullException" error (or
something like that) when I was trying to deploy the
application to an emulator. It was in the preload event
of the FormStack.vb module. It stopped on the following
code..

Public Function Preload(ByVal FormType As Type) As
IStackable
Dim form As IStackable = CType
(Activator.CreateInstance(FormType), IStackable) < Error
was here

Unfortunately I am still just learning the .NET language
so I am not able to do much trouble shooting so I gave up
on it. Any recommendations?

Thanks
 
M

Mike

Thanks for your help. Any chance I could get more info
regarding how you set this up? i.e. Example Code??
 
M

Mark Reddick

Sure. I have a class that I use for any global constants as well as my
global form variables. Like this:

--------------------------
using System;

namespace My.Namespace
{
public class MyGlobal
{
public const string AppName = "My Application Name";

public static Form1 frmForm1;
public static Form2 frmForm2;
public static Form3 frmForm3;

public MyGlobal()
{
}
}
}
--------------------------

To preload the forms, I display a splash form then do the loading then turn
off the splash screen. This is done like this:
-----------------------------

frmSplash = new Splash();
frmSplash.Show();
frmSplash.Refresh();

MyGlobal.frmForm1 = new Form1();
MyGlobal.frmForm2 = new Form2();
MyGlobal.frmForm3 = new Form3();

frmSplash.Close();

-----------------------------

I give the user an option to turn on/off the initial form loading. If they
turn it off, I don't do the code above to preload the forms. I still only
load the form the first time it is called. So, to handle this, whenever I go
to show a form, I do something like this:

------------------------------

if (MyGlobal.frmForm1== null)
MyGlobal.frmForm1 = new Form1();

this.Text = "";
MyGlobal.frmFrm1.ShowDialog();
this.Text = MyGlobal.AppName;

------------------------------------

BTW, I clear the caption of the current form when I'm about to load a new
form as you can see above (this.Text = ""). This is done because the Pocket
PC "Running Programs" list (in the Settings applet) enumerates all open
windows. If you leave the caption on all your forms, the "Running Programs"
list will show an entry for each form. By clearing the caption it causes
"Running Programs" to not list it. This way "Running Progrms" will always
only show the current form and so if the user activates it they will be
brought back to the correct form.


I hope this helps,
Mark
 

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