• WPF 最大化最小化窗口


    public static void FullOrMin(this Window window)
            {
                //如果是全屏,则最小化
                if (window.WindowState == WindowState.Maximized)
                {
                    window.Topmost = false;
                    window.WindowState = WindowState.Normal;
                    window.WindowStyle = WindowStyle.SingleBorderWindow;

                    window.ResizeMode = ResizeMode.CanResizeWithGrip;//设置为可调整窗体大小
                    window.Width = 800;
                    window.Height = 600;

                    //获取窗口句柄 
                    var handle = new WindowInteropHelper(window).Handle;
                    //获取当前显示器屏幕
                    Screen screen = Screen.FromHandle(handle);

                    window.Left = (screen.Bounds.Width - window.Width) / 2;
                    window.Top = (screen.Bounds.Height - window.Height) / 2;

                    window.WindowState = WindowState.Minimized;
                    return;
                }

                //如果是窗口,则全屏
                if (window.WindowState == WindowState.Normal)
                {
                    //变成无边窗体
                    window.WindowState = WindowState.Normal;//假如已经是Maximized,就不能进入全屏,所以这里先调整状态
                    window.WindowStyle = WindowStyle.None;
                    window.ResizeMode = ResizeMode.NoResize;
                    window.Topmost = true;//最大化后总是在最上面

                    //获取窗口句柄 
                    var handle = new WindowInteropHelper(window).Handle;

                    //获取当前显示器屏幕
                    Screen screen = Screen.FromHandle(handle);

                    //调整窗口最大化,全屏的关键代码就是下面3句
                    window.MaxWidth = screen.Bounds.Width;
                    window.MaxHeight = screen.Bounds.Height;
                    window.WindowState = WindowState.Maximized;


                    //解决切换应用程序的问题
                    window.Activated += new EventHandler(window_Activated);
                    window.Deactivated += new EventHandler(window_Deactivated);
                }

            }

            static void window_Deactivated(object sender, EventArgs e)
            {
                var window = sender as Window;
                window.Topmost = false;
            }

            static void window_Activated(object sender, EventArgs e)
            {
                var window = sender as Window;
                window.Topmost = true;
            }

  • 相关阅读:
    Python判断列表是否已排序的各种方法及其性能分析
    Python实现C代码统计工具(四)
    Python代码统计工具
    Python实现C代码统计工具(三)
    Python实现C代码统计工具(一)
    Python标准输出重定向
    为C函数自动添加跟踪语句
    Python2.7字符编码详解
    Python实现Linux命令xxd -i功能
    1124 Raffle for Weibo Followers (20 分)
  • 原文地址:https://www.cnblogs.com/jinhaoObject/p/4963812.html
Copyright © 2020-2023  润新知