I have a desktop PC with a 2560 x 1440 resolution, and a netbook with a 1024 x 600 resolution.
When I RDP-connect with the netbook to the desktop, the screen of the desktop is presented in 1024x600, since the netbook does not allow more. So, there is some re-scaling of the windows, and some kind of 'virtual screen' just changed its size from 2560x1440 to 1024x600.
However, the System.Windows.Forms.Screen.AllScreens
property does not reflect this change, its single array item stays at 2560 x 1440.
How can I detect the 'virtual screen size change' in .NET, using WinForms or WPF?
Thank you
Edit:
I forgot to say, the AllScreens
property changes its value when I debug in Visual Studio (with the vshost.exe host EXE), but as soon as I run the program without a debugger, the AllScreens
property does not reflect the change in screen size.
I was able to detect screen resolution changes from both the desktop computer and from a remote laptop connecting through remote desktop as well as having it report the proper resolution numbers by the following technique:
I just created a sample WinForms program that handles this event:
Microsoft.Win32.SystemEvents.DisplaySettingsChanged +=
SystemEvents_DisplaySettingsChanged;
In my test I had a listbox which displayed the information when the screen changed:
void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
foreach (var screen in System.Windows.Forms.Screen.AllScreens)
{
listBox1.Items.Add("Device Name: " + screen.DeviceName);
listBox1.Items.Add("Bounds: " +
screen.Bounds.ToString());
listBox1.Items.Add("Type: " +
screen.GetType().ToString());
listBox1.Items.Add("Working Area: " +
screen.WorkingArea.ToString());
listBox1.Items.Add("Primary Screen: " +
screen.Primary.ToString());
}
}
I ran the program in release mode outside the debugger on my desktop and then connected from my lower resolution laptop and the numbers changed to reflect the lower resolution.