public class ConstrainedWindow : Window
{
public ConstrainedWindow()
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
private bool IsMaxed = false;
private void btnMax_Click(object sender, RoutedEventArgs e)
{
if (!IsMaxed)
{
var window = Window.GetWindow(this);//获取当前主窗口
var intPtr = new System.Windows.Interop.WindowInteropHelper(window).Handle;//获取当前窗口的句柄
var screen = System.Windows.Forms.Screen.FromHandle(intPtr);//获取当前屏幕
using (System.Drawing.Graphics currentGraphics = System.Drawing.Graphics.FromHwnd(intPtr))
{
int DpiPercent = 96;
double dpiXRatio = currentGraphics.DpiX / DpiPercent;
double dpiYRatio = currentGraphics.DpiY / DpiPercent;
var width = screen.WorkingArea.Width / dpiXRatio;
var height = screen.WorkingArea.Height / dpiYRatio;
this.MinHeight = 0;
this.MinWidth = 0;
this.MaxHeight = height
this.MaxWidth = width
this.WindowState = WindowState.Maximized;
}
IsMaxed = true;
}
}
}
WPF 自定义窗体 最大化的时候遮挡任务栏--解决方案
最新推荐文章于 2024-05-14 16:12:58 发布