0

In the beginning, I have a 4-form desktop program that wants to display every form on a screen depending on a unique identifier for this screen, for example Form 1 on the screen with ID etc and Form 2 on the screen with the ID ....

If all form is run correctly, i need a Way to check whether the screens are connected throughout the program life cycle so that if disconnect one, get a message in the name of the form in which it was displayed and prevent this form from moving to another screen

I tried the following method:

Screen.ALLScreen []

However, this method does not provide an ID depending on the screen, but depending on the sequence of screen connections to the computer.

private void Form1_Load(object sender, EventArgs e)
    {

        Form2 F2= new Form2();
        Form3 F3 = new Form3();
        this.Location = new Point(Screen.AllScreens[0].Bounds.X, Screen.AllScreens[0].Bounds.Y);
        F2.Location = new Point(Screen.AllScreens[1].Bounds.X, Screen.AllScreens[1].Bounds.Y);
        F3.Location = new Point(Screen.AllScreens[2].Bounds.X, Screen.AllScreens[2].Bounds.Y);
        F2.Show();
        F3.Show();}

//here i will check all screens if they are connected throughout the program life cycle

public void checkScreen(){`// rescan all screen`check if there any screen disconnected`if it happened  `send message  form name and close the form or minmize it`}
Ahmad Ali
  • 11
  • 2
  • 2
    Welcome! Would it be possible to post some more code? [mcve]. This will help us help you. Good luck –  Jul 04 '19 at 11:32
  • You'll have to combine this: [WM_POWERBROADCAST](https://learn.microsoft.com/en-us/windows/win32/power/wm-powerbroadcast) and this: [WM_DISPLAYCHANGE](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-displaychange). These notes may also help: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103). – Jimi Jul 04 '19 at 11:42
  • With regard to identifying a particular display: I guess you have to search and look for a library that can obtain EDID/DisplayID data for each display. EDID/DisplayID data _can_ provide the serial number of a display device (unless the device provides incomple EDID/DisplayID data lacking serial number information). If there is no such .NET library, you might want to look for a native DLL with C-style function exports which you could P/Invoke. If there is not even such a native DLL to be found, i guess you have to code this yourself :-( –  Jul 04 '19 at 11:42
  • ... and you could register for Power changes notifications: [RegisterPowerSettingNotification](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerpowersettingnotification), which could be combined with: [RegisterPointerInputTarget](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerpointerinputtarget) (to *centralize* the messages management). – Jimi Jul 04 '19 at 12:28
  • You can read EDID data with WMI (I just posted a sample in C++, but it is easier in C#) I have only 1 monitor so I cannot test with several ones, but I get for my monitor : `Instance Name = DISPLAY\PHLC085\4&20634529&0&UID65793_0 User Friendly Name = 247ELH Manufacturer Name = PHL Product Code ID = C085 Serial Number ID = AU01307001613` – Castorix Jul 04 '19 at 15:56
  • can you send me a link your post – Ahmad Ali Jul 05 '19 at 11:31

0 Answers0