I wanted to send my application to the background. Simple enough, I just wrote Form.Hide() (or Form.visible = false). this did the job, my application was minimized and running at the background. At some point I wanted to use my application again, I clicked the applications icon, but nothing happend, I went to the running programs list in the settings, but my application was not there! my application was running in the background, and there was no way for me to close or access it!
Lucky enough, I used the Remote Process Viewer to find my application and kill it.
It seems that when Hiding a form (form.Hide()), The form is hidden from the user, and not only minimized. Funny that when clicking the “x” (which for some reason is called smart minimize), the application is minimized and sent to the background, where as using the hide() or visible=false, the application is hidden from the user and is not accessible.
The Form class has a property which is called WindowsState. This property indicates the visual state of the form. unfortunately, the states that Windows Mobile/ .Net compact framework supports are ‘Normal’ and ‘Maximized’ and there is no support for the ‘Minimized’ state.
The solution for this problem is to call the Native function ShowWindow() with the ‘Minimized’ property:
[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_MINIMIZED = 6;
public void Hide()
{
ShowWindow(_form.Handle, SW_MINIMIZED);
}
Hiding the application this way, will not “hide” the application from the user, but only minimize it and the application will be “reachable” from the running programs list.