C# 全屏控制

C# 全屏控制_第1张图片

private void fullScreenHandler(bool isFullScreen)
        {
            if (isFullScreen)
            {
                this.WindowState = (WindowState)FormWindowState.Maximized;
                this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
                this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
                this.Topmost = true;
                this.ResizeMode = System.Windows.ResizeMode.NoResize;
                this.WindowStyle = System.Windows.WindowStyle.None;
            }
            else
            {
                this.WindowState = (WindowState)FormWindowState.Normal;
                this.Width = 1920;
                this.Height = 1080;
                this.Topmost = false;
                this.ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip;
                this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
            }
            this.Left = 0.0f;
            this.Top = 0.0f;
        }
 
        protected override void OnKeyUp(System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                fullScreenHandler(false);
            }
            if (e.Key == Key.Enter)
            {
                fullScreenHandler(true);
            }
        }
 
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = false;
        }


你可能感兴趣的:(C# 全屏控制)