代码如下:主要就是利用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健的响应处理就更完美了.
本文介绍了一种在Windows应用程序中使窗体始终保持在最前的技术。通过使用P/Invoke调用Win32 API函数SetForegroundWindow和GetCapture,实现窗体置顶功能,并附带示例代码。
3183

被折叠的 条评论
为什么被折叠?



