zoukankan      html  css  js  c++  java
  • C#SetWindowPos窗口置顶

    C#SetWindowPos窗口置顶

    [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);


    这样,新打开的窗体就是置顶了

  • 相关阅读:
    springboot对JPA的支持
    Hibernate-什么是orm思想
    利用Struts拦截器完成文件上传功能
    Struts2的CRUD
    struts2的初步认识
    Maven搭建
    java虚拟机
    Map集合
    Set集合(TreeSet)
    Set集合的
  • 原文地址:https://www.cnblogs.com/hongfei/p/2826005.html
Copyright © 2011-2022 走看看