zoukankan      html  css  js  c++  java
  • WinForm 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);

  • 相关阅读:
    API
    MVC判断是否登录
    MVC收藏店铺
    MVC显示界面
    MVC登录
    MVC登录跳转到显示
    MVC退单
    MVC判断登录
    Oracle 千位符转换,及格式转换
    【转】Java 服务端 和 C# 客户端 实现 Socket 通信
  • 原文地址:https://www.cnblogs.com/51net/p/10983112.html
Copyright © 2011-2022 走看看