Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

C# Screen.AllScreens Not Updating (Changes in display resolution/position not reflected in Screen class)

$
0
0

Greetings,

I am working on an application which automatically sizes a Windows Form to the size of a screen. I am using the Screen.AllScreens property to acquire a list of Screen objects, and using the Bounds of that object to size my form.

An issue I am having is with updates in the displays' size and position not being reflected in the Screen.AllScreens property, thus resulting in misaligned and improperly scaled forms.

A quick example of this follows:

[SNIP] //Here is an example "forced" sample of what I am trying to accomplish. //Align all the screens to start with fitFormsToScreens(Screen.AllScreens); //At this point, the forms are all properly fitted //Now black magic occurs that changes the resolution of one or more of the displays

//These resolution changes are reflected in the control panel alterDisplayResolutions(); //Now attempt to realign the screens. fitFormsToScreens(Screen.AllScreens); //At this point the screens are NOT properly fitted. //Breaking the debug at the above method call reveals that //theScreen.AllScreens property has not changed [SNIP]

I have made an attempt (based off of THIS question) to force the Screen.AllScreens property to update. It does not fix the issue however. I do not know if I am approaching the issue in the correct manner, or if I am simply using the wrong uint, IntPtr, etc.

My attempt is shown below:

[DECLARATION]

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);

[DECLARATION]


[METHOD CALL]

//we need to reset AllScreens?

IntPtr HWND_BROADCAST = (IntPtr)0xffff;

uint WM_DISPLAYCHANGE = 0x007E;

PostMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, UIntPtr.Zero, IntPtr.Zero);

[METHOD CALL]

[TL;DR]

I would like to know if there is a way to ensure that the Screen.AllScreens property is updated at any given point in time.

Thank you in advance for any assistance you can provide.


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>