加入收藏 | 设为首页 | 会员中心 | 我要投稿 南京站长网 (https://www.025zz.com.cn/)- 自然语言处理、建站、经验、云计算、图像分析!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

C# SetWindowPos窗口置顶使用介绍

发布时间:2023-06-12 16:00:37 所属栏目:语言 来源:网络
导读:   代码如下:



  [DllImport("user32.dll", CharSet = CharSet.Auto)]



  private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int
  代码如下:
 
  [DllImport("user32.dll", CharSet = CharSet.Auto)]
 
  private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
 
  /// <summary>
 
  /// 得到当前活动的窗口
 
  /// </summary>
 
  /// <returns></returns>
 
  [DllImport("user32.dll", CharSet = CharSet.Auto)]
 
  private static extern System.IntPtr GetForegroundWindow();
 
  哪个窗体想要置顶,在Form_Load中加上
 
  SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后参数也有用1 | 4 
 
  具体说明,看API函数说明
 
  如果是用点击一个按钮后弹出新窗体,并置顶,则:
 
  代码如下:
 
  Form2 frm = new Form2();
 
  frm.Show();
 
  SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
 
  这样,新打开的窗体就是置顶了
 

(编辑:南京站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章