Bring a .NETCF Form to the foreground

Sometimes calling BringToFront for your form is not enough to bring your app to the foreground. You can P/Invoke SetForegroundWindow which will activate your app and bring the window to the front of the Z-Order:-


C#

public void SetForegroundWindow()
{
    this.Capture = true;
    IntPtr hwnd = OpenNETCF.Win32.Win32Window.GetCapture();
    this.Capture = false;
    OpenNETCF.Win32.Win32Window.SetForegroundWindow(hwnd);
}

or VB

Public Sub SetForegroundWindow
    Me.Capture = True
    Dim hwnd As IntPtr = OpenNETCF.Win32.Win32Window.GetCapture()
    Me.Capture = False
    OpenNETCF.Win32.Win32Window.SetForegroundWindow(hwnd)
End Sub

Advertisements