Form.Owner


If you simply use ShowDialog to display another form:
a) The new form (specifically its caption/text) appears in the "running programs list"
b) The original form also appears in the list, which means you can navigate to it (although it appears disabled once activated)
c) There is potential for closing the second form and returning to another window on the PPC (the original form has moved back in the z-order)

With CF 2.0 you can use the Owner property of the Form and hence get rid of every problem from the above list. Do not confuse the Owner property with the Parent property, which is inherited from Control and is not intended to be used with forms

Run the following snippet:

using (Form2 form2 = new Form2())
{
form2.Owner = this;
form2.ShowDialog();
}

...you'll notice that only one entry for your application exists in the running list. The only potentially strange thing is that it has the caption of the first form (while the body of the form is clearly that of Form2)! This is easily rectified with the following modification:

using (Form2 form2 = new Form2())
{
form2.Owner = this;

string title = this.Text; //make a copy of the original caption
this.Text = form2.Text; //set our caption to the form

form2.ShowDialog();

this.Text = title; //restore the original caption
}

Sample Project:
http://winmobile.euweb.cz/#Post12

0 comments:

Post a Comment