Maintaining one visible form with CF2.0

Hi,

I have recently created a CF2.0 Pocket PC application using VS 2005 Beta 2 after being inspired by the following white paper:

"Northwind Pocket Service: Field Service for Windows Mobile-based Pocket PCs"

available at:

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

When opening and closing all forms in my application I use the method used in the white paper which is described in an extract from the white paper below:

+++++++++++++++++++++++++++++++++

The code that runs when the first menu option (Plan) is selected looks like this:



Cursor.Current = Cursors.WaitCursor;
PlanForm planForm =new PlanForm(this);
planForm.ShowDialog();

During the load of the new form, the wait cursor is shown. Also note that the current form instance is passed as a parameter to the child form (PlanForm) to allow the child form to control the parent form's visibility.

This is what the PlanForm constructor looks like:



public PlanForm(Form parentForm)
{
InitializeComponent();
this.parentForm = parentForm;

}

The parent form instance is saved in a private variable (parentForm) that is used in the form's load event:



privatevoid PlanForm_Load(object sender, EventArgs e)
{

parentForm.Hide();
Cursor.Current = Cursors.Default;
}

It is used to hide the parent form and remove the wait cursor. Also, it is used when the form closes:



privatevoid PlanForm_Closing(object sender, CancelEventArgs e)
{
parentForm.Show();
}

The parent form is shown again. The reason for doing this is that there will be only one instance of the application in the current running programs list (Start > Settings > System > Memory > Running Programs).

+++++++++++++++++++++++++++++++++

This works fine for a CF1.1 application created in VS2003. However when I use the above method in a CF2.0 application, the application momentarily disappears when a form is shown. I think this is due to the load event running 'parentForm.Hide();' before the form that is being loaded is visible.

Please can someone help me out with this issue?

Best Regards,

Craig Harrison

[3723 byte] By [CraigHarrison] at [2008-2-13]
# 1
Some things have changed with CF 2.0 in that area (for the better).

See if this post helps you:
http://www.danielmoth.com/Blog/2005/06/formowner-in-netcf-20.html

If not, please describe your goal so we can reccommend how you can achieve it.

Cheers
Daniel

DanielMoth at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 2

Hi Daniel,

My goal is just 'good practice'. In the white paper example the 'owner' form was hidden when a new form was opened and shown again when the new form was closed. Is this necessary if I follow the example in your blog as shown below (Minus caption adjustment code)?



Form2 f = new Form2();
f.Owner = this;
f.ShowDialog();

Thanks,

Craig Harrison

CraigHarrison at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 3

Never mind. LOL
I am with Daniel now after test.

AllenAlper at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 4
Hi Craig
From memory, no it is not needed. "Try it and see" is always my advice! If you observe different results, feel free to post back.
Cheers
Daniel
DanielMoth at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...