views:

1840

answers:

4

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?

+1  A: 
Joel Coehoorn
I agree. WinCE is different from Windows client or server.
Lex Li
I know about the Form.MinimizeBox property, which changes the behavior of the "Ok" button between "minimize" and "close". What I'm looking for is a way to minimize a form by code.
Martin Plante
A: 

Call Hide() on your active form.

ctacke
That's not the behavior I'm looking for, since the form becomes invisible to Windows Mobile. It doesn't see the app anymore. I'm really looking for a way to switch back to "the previous process" by code.
Martin Plante
Well WinMo doesn't have Minimize state for a Window. What do you mean it becomes "invisible"? And when you hide your form, the last Form shown will be at the top unless the Today screen has been brought forward in Z-order or the other process was terminated.
ctacke
+3  A: 

This is your answer.

http://christian-helle.blogspot.com/2007/06/programmatically-minimize-application.html

Thank you very much. I should have tried that!
Martin Plante
A: 

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/Invoking ShowWindow(Form.Handle, 6), where 6=SW_MINIMIZE, would minimize the application to the taskbar but only when Form.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.

Jason Morse