I have a laptop that has both HDMI and VGA connectors; my TV is connected to the HDMI port (set at a resolution of 1600x900), and my desk monitor is connected to VGA (at an old-fashioned 1280x1024). The GPU does not allow for both external ports to be used simultaneously, so I end up having to switch between the one and the other, depending on whether I want to watch my shows and movies or sit behind the computer.
So far, so good... but (me being OCD about that stuff) I want to have a different wallpaper depending on the active config (laptop + TV or laptop + VGA), set by some script...
To catch the change between setups (Intel Graphics, using one of two preset profiles) I need something that monitors the active monitors for changes.
I've found a simple solution using SystemEvents.DisplaySettingsChanged, but this only works when I run the code from the VB.Net IDE. As soon as I compile and run the exe, the event doesn't seem to get triggered anymore.
I also tried a continuous loop using the Windows.Forms.Screen.AllScreen array, but the same applies: runs like a charm from within the IDE, but when compiled, it never detects the change.
Skeleton code for the first option (run as a console app):
Imports Microsoft.Win32
Imports System.Threading
Module Module1
Public Sub MyEH2(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("Display has changed")
' Actual code do change wallpaper comes here, natch
End Sub
Sub Main()
AddHandler SystemEvents.DisplaySettingsChanged, AddressOf MyEH2
While 1
Thread.Sleep(1000)
End While
End Sub
End Module
My question is: why does this work when started within the IDE, but not when compiled as an EXE? (In other words: why doesn't the compiled version detect the changes?)
I'm running Windows 7 Home Premium and using VB.Net 2012 (Express)