Wpf window changes when the computer is locked

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; 

All this is normal, until I close my computer (WIN + L), when I return, the window resized itself on only one monitor.

What I want to do is to prevent downsizing, as I draw on the canvas on the second monitor, and when resizing occurs, all this is lost.

Any thoughts on how I can prevent this?

Hooray!

+2
source share
1 answer

You can use the Unlock / Lock event in .NET. Save the height, width, and position of the window during the lock event and restore it to the 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 } } 
+1
source

All Articles