is there an easy way to hook to an event that is triggered on change of global screen resolution?
There are two events - SystemEvents.DisplaySettingsChanged
and SystemEvents.DisplayedSettingsChanging
which you can handle.
Note that both events are static and you will need to detach your handlers before exiting from your program.
Handle the following event:
Microsoft.Win32.SystemEvents.DisplaySettingsChanged
You may refer to this page for more details.
You may also wanna see the msdn article on SystemEvents class.
try this simple code
using Microsoft.Win32;
SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
MessageBox.Show("Resolution Change.");
}
and don't forget this line using Microsoft.Win32;
Sure you don't have to unsubscribe to static events (or any events) if your program (process) is dying. The OS will take care of releasing all memory of your process to the OS. However, if you subscribe to a static event or to any event pointing to an object with a longer lifetime than your object subscribing, and you want that object to be eligible for GC - you need to unsubscribe (-=) to the event.
AND it is always good practice to always unsubscribe to all events. You never know when the lifetime of your objects are changed (by someone else) during the lifespan of your source code / product...