29

is there an easy way to hook to an event that is triggered on change of global screen resolution?

djot
  • 2,952
  • 4
  • 19
  • 28
Matze
  • 1,402
  • 2
  • 17
  • 24

3 Answers3

39

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.

G S
  • 35,511
  • 22
  • 84
  • 118
4

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...

Jan Romell
  • 41
  • 1
3

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;

Ramgy Borja
  • 2,330
  • 2
  • 19
  • 40