代码如下:主要就是利用SetForegroundWindow
[DllImport("coredll.dll", EntryPoint = "GetCapture")]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint = "SetForegroundWindow")]
private static extern bool SetForegroundWindow(IntPtr hwnd);
public bool SetFormTop(Form form)
{
form.Capture = true;
IntPtr hwnd = GetCapture();
form.Capture = false;
return SetForegroundWindow(hwnd);
}
private void bt_Click(object sender, EventArgs e)
{
Form1 fdlg = new Form1();
string title = this.Text;
this.Text = string.Empty;//隐藏窗口标题
fdlg .ShowDialog();
this.Text = title;
SetFormTop(this);//在上个Form窗口返回的时候,把自己设置到最上面显示
}
如果是在Smartphone中,那么结合上次说的对Back Key健的响应处理就更完美了.