Screen Object: Recreating or Updating

Quagmire

Newcomer
Joined
Jun 5, 2005
Messages
3
I use the Screen object to get the working area of the desktop (i.e. minus the task bar).

I would like to be able to get updated values if the user moves the taskbar, adds another desktop bar object, etc. while the program is running.

However, as the documentation says: "The constructor for this object is not public, so you cannot explicitly create a Screen object. The object is created when you call its public methods."

So if I call get Screen.WorkingArea, then resize the taskbar and get the value again, it doesn't change!

Is there any way to force this kind of object to be disposed of and recreated?

It has no Dispose method.

This isn't a critical feature for my program or anything because it isn't terribly likely to happen, but I like to cover my bases. And I've gotton sorta curious if its possible.
 
A maximized window's bounds will be close to the desktop working area, but slightly larger (because of borders?). The discrepancy could be recorded when the program starts and used whenever you want to examine the working area, but, still, there is no event or anything that I know of for when the working area has changed.
 
PrimaryScreen is a Shared/static member of the Screen class. You could therefore call Screen.PrimaryScreen.WorkingArea to get the current working area of the primary screen. As marble_eater says, though, there are no events for you to handle so you would have to check on demand. You could set a timer to check intermittently, if necessary.
 
Rather than PrimaryScreen, I have been checking the working area of all the screens in AllScreens, but the problem is that the object persists with old data even after changes are made by the user.

I don't know exactly how long I would have to wait for it to be garbage collected, allowing me to get fresh info, but it is definitely too long.
 
I tested some code and found a bit of an anomoly. If you change the resolution of a monitor, the change is reflected in the WorkingArea of the screen. If you change the area of the taskbar, however, the change is not reflected. If you then restart the app and check again, the change is reflected. That seems like a potential bug to me. You may want to do some reading on the Screen class to make sure that this is not by design for some obscure reason.
 
Thanks, I didn't know that it got noticed if you changed the resolution. That does seem odd and possibly buggy.
 
Back
Top