计算机锁定时 Wpf 窗口调整大小

发布于 2024-08-21 21:24:01 字数 407 浏览 2 评论 0原文

我有一个Window设置为我的显示器的高度和宽度:

var r = System.Drawing.Rectangle.Union( System.Windows.Forms.Screen.AllScreens[0].Bounds, System.Windows.Forms.Screen.AllScreens[1].Bounds );
Height = r.Height;
Width = r.Width;

这一切都很好,直到我锁定我的计算机(WIN + L),当我回来时,窗口已调整大小以位于一台显示器上仅有的。

我想要做的是防止尺寸减小,因为我在第二台显示器上的画布上绘图,并且当调整大小时,这一切都丢失了。

关于如何防止这种情况,有什么想法吗?

干杯!

I have a Window set to the height and width of my monitors:

var r = System.Drawing.Rectangle.Union( System.Windows.Forms.Screen.AllScreens[0].Bounds, System.Windows.Forms.Screen.AllScreens[1].Bounds );
Height = r.Height;
Width = r.Width;

This is all fine until I Lock my computer (WIN+L), when I come back the window has resized itself to be on one monitor only.

What I want to do is prevent the decrease in size, as I'm drawing on a canvas on the second monitor, and when the resize occurs, this is all lost..

Any thoughts on how I can prevent this?

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2024-08-28 21:24:01

您可以在.NET 中使用解锁/锁定事件。在锁定事件期间存储窗口高度、宽度和位置,并在解锁事件时恢复它。确保添加“使用 Microsoft.Win32

SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);

private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
    if (e.Reason == SessionSwitchReason.SessionUnlock)
    {
        //Put resize logic here
    }
    else if (e.Reason == SessionSwitchReason.SessionLock)
    {
        //Put size store logic here
    }
}

You can use the Unlock/Lock event in .NET. Store your window height, width and position during the lock event and restore it on an Unlock event. Make sure you add "using Microsoft.Win32"

SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);

private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
    if (e.Reason == SessionSwitchReason.SessionUnlock)
    {
        //Put resize logic here
    }
    else if (e.Reason == SessionSwitchReason.SessionLock)
    {
        //Put size store logic here
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文