Detect when a new display is connected

I am writing an application that requires two displays: one for the control panel, the other for output. I have this: if there is only one display, the application shows both forms on it, but if there are two, the output form goes to the other. The problem is that this only happens when the application starts. In other words, if the application is already running before the second display is connected, nothing happens if the user does not send the output to the new display manually (provided that he knows how to do it). I want that when a new display is connected, the output form is automatically sent to him even while the application is running. I think this is due to polling the port in the stream, but I do not know how to do this. Can anyone help on how to do this? If there is a better solution, I will gladly welcome it.

(I would provide part of the code, but I type it from the phone)

+7
source share
3 answers

Look here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc.aspx

Here is an example that should help you. Try something like this:

protected override void WndProc(ref Message m) { const uint WM_DISPLAYCHANGE = 0x007e; // Listen for operating system messages. switch (m.Msg) { case WM_DISPLAYCHANGE: // The WParam value is the new bit depth uint width = (uint)(m.LParam & 0xffff); uint height = (uint)(m.LParam >> 16); break; } base.WndProc(ref m); } 
+8
source

You can turn on a timer that checks, for example. every 2 seconds if the number of screens is more than one. The code might look like this:

 timer_tick() { if(Screen.AllScreens.Length >= 2) { //run code to use the second screen } } 

Easy to use for beginners in C #.

0
source

You can use WndProc and Screen.AllScreens.Length :

 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void WndProc(ref Message m) { if (Screen.AllScreens.Length > 1) //example { } base.WndProc(ref m); } 

Additional Information:

0
source

All Articles