SetForegroundWindow

  • Thread starter Thread starter ME
  • Start date Start date
M

ME

In some cases a form did not come forward in .NET CF 1.0. Does .NET CF 2.0
have better way to do this now? I noticed that the forms now offer handles.

In version 1.0 it was necessary to use OpenNETCF:
http://www.peterfoot.net/CommentView,guid,a4bca0e4-439b-411a-87cd-0950e9d16b10.aspx

Snipit from Peter's page:
public void SetForegroundWindow()
{
this.Capture = true;
IntPtr hwnd = OpenNETCF.Win32.Win32Window.GetCapture();
this.Capture = false;
OpenNETCF.Win32.Win32Window.SetForegroundWindow(hwnd);
}

Thanks,

Matt
 
You don't _have_ to use OpenNETCF - you could declare the P/Invokes
yourself. Having the form handle allows you to cut out the first step so
instead you can use:-
public void SetForeground()
{
SetForegroundWindow(this.Handle);
}

The P/Invoke for SetForegroundWindow is simple:-

[DllImport("coredll.dll", SetLastError=true)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

Another option you have for a form which is to always display above others
is the TopMost property which will keep your form above others in the
z-order.

Peter
 
Back
Top