Under the .NET Compact Framework, there is no FormWindowState.Minimize value. How can I minimize my application, so that it remains active and available, but gives back the focus to the previous application?
I'm developing on the generic WinCE (4.2 and 5.0) so I'm not sure if my solution will work for your Windows Mobile problem.
In our scenario our form needed to take up the entire screen (including hiding the taskbar), have no title bar, ability to minimize through code, and when minimized it would show the application icon in the taskbar (so it can be restored) giving focus to the previous program on the application stack. It doesn't sound too bad but in practice I could not meet all the requirements at the same time required some trickery.
As others have posted there's no Form.Minimize() on the compact framework.
Form.Hide()
gave me no way to restore the app. P/InvokingShowWindow(Form.Handle, 6)
, where 6=SW_MINIMIZE, would minimize the application to the taskbar but only whenForm.FormBorderStyle = Normal
(instead of None) however this would show the app title bar.- I needed to set
Form.WindowState = Normal
instead of Maximized otherwise when the app was minimized it would immediately restore.
In the end I put together the following to get what I wanted. It involved manually setting the application size by filling the screen AND with some extra height so I could skew the application up and move the titlebar off the viewable screen.
public class MyForm
{
public MyForm()
{
InitializeComponent();
NativeMethods.HideTaskbar();
FormBorderStyle = FormBorderStyle.FixedSingle;
WindowState = FormWindowState.Normal;
Rectangle screenBounds = Screen.PrimaryScreen.Bounds;
int taskBarHeight = SystemInformation.MenuHeight;
NativeMethods.MoveWindow(Handle,
0, -taskBarHeight,
screenBounds.Width, screenBounds.Height + taskBarHeight);
}
public void HandleMinimize()
{
NativeMethods.ShowTaskBar();
NativeMethods.ShowWindow(Handle, WindowShowStyle.Minimize);
}
Intercepting the app restore event to hide the taskbar was way more complicated and since the originating author didn't mention the taskbar I will not go into it.
All the static NativeMethods class methods are wrappers for P/Invoke statements. Refer to coredll section in http://www.pinvoke.net for more information on implementing these.