Reputation: 53
I am trying to get Screen width and Height of my System on SizeChanged
Event.
It works fine in all cases excluding:
Change Screen Size to 1024 X 765 then Run my Application its works fine.
Change Screen Size Again to Another Resolution while my application running got Width and height of my Previous Resolution not Current.
I have used screen.primaryscreen.bounds.width
on Window_SizeChanged
Event.
Upvotes: 2
Views: 2781
Reputation: 1294
You can monitor the SystemEvents
for changes.
using Microsoft.Win32;
Add this to your constructor or the like:
SystemEvents.DisplaySettingsChanged +=
new EventHandler(SystemEvents_DisplaySettingsChanged);
Here's the event handler. I have the data bound to 2 TextBoxes so I could see the values change as I messed with the resolution, including telling it to revert.
void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
data.ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
data.ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
}
In your case, just change the assignment to point to where you want to store it.
Upvotes: 2