Tuesday, March 18, 2008

How to allow minimize being in a modal dialog on Pocket PC using the .Net CF

An interesting question came up today at the Mobility Metro train the trainers workshop in London: How can we allow the Pocket PC user to minimize the application even when he is in a modal dialog?

This is a particular requirement received by an attendee, and it was a little bit challenging problem. I did a small spike on this, and this is my suggested approach.

First of all, we cannot use Form.ShowDialog(), because it shows the 'OK' button at the top right corner, and ideally we should keep the standard 'X' smart minimize button there.

The solution is to use Form.Show() and handle the Form.Closed event of the dialog. We also should take care of the dialog Owner property in order to show only one entry on the Running Programs List.

private void menuItem1_Click(object sender, EventArgs e)
Dialog dialog = new Dialog();

//Prepare the app to be 'Running Programs Aware'
this.Text = dialog.Text;
dialog.Owner = this;

//Subscribe to the dialog closed event
dialog.Closed += delegate(object s2, EventArgs e2)
//Do something when the dialog is closed
label1.Text = string.Format("DialogResult = {0}", dialog.DialogResult.ToString());
//Update the form text back
this.Text = "MainForm";

Here you can find the spike sourcecode:



No comments: