wpf 最大最小化窗口详细
2021-06-22 13:04
标签:void idt hand size ini mod scree 进入 mos 转自分享 public static void Win(this Window window) window.ResizeMode = ResizeMode.CanResizeWithGrip;//设置为可调整窗体大小 //获取窗口句柄 window.Left = (screen.Bounds.Width - window.Width) / 2; window.WindowState = WindowState.Minimized; //如果是窗口,则全屏 //获取窗口句柄 //获取当前显示器屏幕 //调整窗口最大化,全屏的关键代码就是下面3句 } static void window_Deactivated(object sender, EventArgs e) static void window_Activated(object sender, EventArgs e) wpf 最大最小化窗口详细 标签:void idt hand size ini mod scree 进入 mos 原文地址:https://www.cnblogs.com/pengde/p/10217163.html
{
//如果是全屏,则最小化
if (window.WindowState == WindowState.Maximized)
{
window.Topmost = false;
window.WindowState = WindowState.Normal;
window.WindowStyle = WindowStyle.SingleBorderWindow;
var handle = new WindowInteropHelper(window).Handle;
//获取当前显示器屏幕
Screen screen = Screen.FromHandle(handle);
window.Top = (screen.Bounds.Height - window.Height) / 2;
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);
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);
}
{
var window = sender as Window;
window.Topmost = false;
}
{
var window = sender as Window;
window.Topmost = true;
}