• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    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);

    这样,新打开的窗体就是置顶了
    您可能感兴趣的文章:
    • C#中隐式运行CMD命令行窗口的方法
    • C# WinForm中禁止改变窗口大小的方法
    • C# Winform中实现主窗口打开登录窗口关闭的方法
    • c# winform窗口一直置顶显示在桌面最上方或最底层的方法
    • C#获取进程的主窗口句柄的实现方法
    • 解决C#获取鼠标相对当前窗口坐标的实现方法
    • C# WinForm窗口最小化到系统托盘
    • C# Winform窗口之间传值的多种方法浅析
    • C# Winform 让整个窗口都可以拖动
    • C# WindowsForm程序同时启动多个窗口类
    上一篇:ASP.NET MVC DropDownList数据绑定及使用详解
    下一篇:C# SetCursorPos简介及使用说明
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    C# SetWindowPos窗口置顶使用说明 SetWindowPos,窗口,置顶,使用说明,