views:

178

answers:

1

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!

+1  A: 

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
    }
}
masenkablast
Excellent, that solved it!
Chris
@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
@Chris - It's OK. I've solved the problem a different way.
ChrisF