I dispose of the About form as it will rarely be viewed.
The reason to use SetForegroundWindow is to ensure that the main form will
be displayed after the secondary form is closed. If the secondary form is
active and the user switches to another application and then back to the
secondary form and closes it then the main form will not be the active
window, the other application will be the active window. The
SetForegroundWindow will make the main form active and display it. Or at
least this is what happened on CF1...
=== Posted with Qusnetsoft NewsReader 3.3
----- Original Message -----
From: "Ginny Caughey [MVP]" <
[email protected]> Sent:
Thu, 13 Jul 2006 14:33:52 Subject: Re: can't close form
Brooke,
A couple of things - forms are not automatically disposed when they're
closed by design to improve performance in case you need them again. If
the
CF gets low on resources, it will take action then.
And all you really need to do to hide a parent form from the Running
Programs list is to set its Text property to "" before you call ShowDialog
on the new form and then set it back when you return. And if you launch
the
secondary form using ShowDialog, even if a user attempted to activate the
primary form from the Running Programs list (assuming that you didn't hide
it by setting the Text to "") then the secondary form would still be
activated and not the primary one.
--
Ginny Caughey
Device Application Development MVP
Brooke said:
Here is the code that I usually use to show secondary modal forms. This
approach will only show one id for your form if you bring up a task
manager or the Running Programs list.
This example is for an About form that is launched from a menu pick.
#region External Dll calls
[DllImport("Coredll.dll")] public static extern IntPtr FindWindow(
string lpClassName, string lpWindowName);
[DllImport("Coredll.dll")] public static extern bool
SetForegroundWindow(IntPtr hWnd);
#region Menu "Help" - "About" event
private void mnuHelpAbout_Click(object sender, System.EventArgs e) {
frmAbout about = new frmAbout();
string temp = this.Text;
bool sipState = sipMain.Enabled;
sipMain.Enabled = false;
this.Text = temp;
sipMain.Enabled = sipState;
IntPtr hwnd = FindWindow( null, this.Text);
if ( hwnd != IntPtr.Zero )
SetForegroundWindow( hwnd );
You will have to place the "External DLL calls" region in your form
class.