2

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!

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42

1 Answers1

1

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
    }
}
sidney.andrews
  • 5,146
  • 3
  • 23
  • 29
  • @Chris. Can you post your working code? I've tried this and can't get it to work. Either by the time the `SessionLock` event is fired the window has already been resized or the restore isn't working on the `SessionUnlock` event. – ChrisF May 19 '10 at 22:31