WPF窗口置顶
    public class TopMostTool
    {
        public static int SW_SHOW = 5;
        public static int SW_NORMAL = 1;
        public static int SW_MAX = 3;
        public static int SW_HIDE = 0;
        //窗体置顶
        public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        //取消窗体置顶
        public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);   
        //不调整窗体位置
        public const uint SWP_NOMOVE = 0x0002;    
        //不调整窗体大小
        public const uint SWP_NOSIZE = 0x0001;    
        /// <summary>
        /// 是否显示最前
        /// </summary>
        public static bool isFirst = true;
        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
        [DllImport("user32.dll", EntryPoint = "ShowWindow")]
        public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow);
        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        /// <summary>
        /// 在外面的方法中掉用这个方法就可以窗体始终置顶
        /// </summary>
        /// <param name="Name">需要置顶的窗体的名字</param>
        public static void setTop(string Name)
        {
            IntPtr CustomBar = FindWindow(null, Name);
            if (CustomBar != null)
            {
                if(isFirst) SetWindowPos(CustomBar, TopMostTool.HWND_TOPMOST, 0, 0, 0, 0, TopMostTool.SWP_NOMOVE | TopMostTool.SWP_NOSIZE);
            }
        }
    }
                版权声明:
                                    
作者:亦灵一梦                                    
链接:https://blog.haokaikai.cn/2020/program/aspnet/974.html
                                    
来源:开心博客                                    
文章版权归作者所有,未经允许请勿转载。
                                
                        THE END
                    
                    
                    1
        
                        二维码        
                
                        海报        
        
            
            WPF窗口置顶
            
                    public class TopMostTool
    {
        public static int SW_SHOW = 5;
        public static int SW_NORMAL = 1;
        public static int SW_MAX ……