In the UI that contains multi-level pages, you should be allowed to select the top-level window to work. However,. Net CF does not provide a method to force the window to the front end, but Win32API provides this method -- SetForegroundWindow function: http://msdn.microsoft.com/en-us/library/ms940024.aspx
This function is suitable when there are multiple forms in the program and the form to be controlled is visible to the user.
The BringWindowToTop http://msdn.microsoft.com/en-us/library/aa452899.aspx provides similar functionality.
In addition, FindWindow http://msdn.microsoft.com/en-us/library/aa453070.aspx can find the form you want, just know the name of the form (2nd parameters) can be, but the premise is that the form is alive, but it runs below.
The following is the test code:
1. create two new forms and add a ButtonCode on Form1
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace toplevel
{
Public partial class Form1: Form
{
Private Timer timer1;
Private Form2 fm2;
Public Form1 ()
{
InitializeComponent ();
Fm2 = new Form2 ();
// Fm2.Visible = true;
This. timer1 = new Timer ();
This. timer1.Interval = 5000;
This. timer1.Tick + = new EventHandler (timerstmtick );
This. timer1.Enabled = true;
}
[DllImport ("coredll. dll")]
Public static extern IntPtr GetFocus ();
[DllImport ("coredll. dll")]
Public static extern int SetForegroundWindow (IntPtr hWnd );
[DllImport ("coredll. dll")]
Public static extern IntPtr FindWindow (string lp1, string lp2 );
[DllImport ("coredll. dll")]
Public static extern int BringWindowToTop (IntPtr hWnd );
Private void timereffectick (object sender, EventArgs e)
{
IntPtr hWnd = FindWindow (null, "Form2 ");
If (hWnd = IntPtr. Zero)
MessageBox. Show ("window is null ");
SetForegroundWindow (hWnd); // OK
// BringWindowToTop (hWnd); // OK
}
Private void button#click (object sender, EventArgs e)
{
Fm2.Show ();
}
}
}
Click Button1 to display Form2 and then minimize it and return to Form1. After the Timer time is reached, Form2 will be placed on it.
In addition, pay attention to fm2.Show () instead of fm2.ShowDialog (), because ShowDialog () will execute the next command until the form is closed.