Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect the visibility of a control?

How to detect if a control is visible to a user? I have a control that displays status of application, and I want it to be updated (it's value to be updated, for example, increase the value of a progress bar, or change a label's Text property) only if a user sees it. No need to update it if a user has minimized the form that contains this control, or if another form overlaps this control. I just don't want to do extra calculations if the control isn't visible any way. Also, how do I detect the events that hide/show this control?

like image 401
Bogdan Verbenets Avatar asked Nov 25 '22 11:11

Bogdan Verbenets


1 Answers

This seems to be one of the topics which is frequently asked and which has many possible solutions, depending on the context.

First, for reference sake, some links to old discussions I stumbled over during my research:

  • How to check absolute control visibility and how to be notified for changes of absolute visibility
  • C# winform check if control is physicaly visible

starting position: An IDE for heterogenous systems with plenty of different hardware and many different transport layers where some are really slow. One feature is to display memory values of remote hw in editors. A typical use case is to have >20 editors open, where each displays between 1 and 100 different values.

Because the transport layers are limited in bandwith I was looking for a solution to "prioritise" the data acquisition.

(partial) solution: A visibility tracker which basically manages a specialised adapter for the control itself and every ancestor control. The adapter handles the visibility dependent on the ancestors type, ie. for a Control, it's just instance.Visible, for a TabPage I check which page is selected, ... The manager's housekeeping then is just to keep track of parent-changes for all the ancestors so that it tracks the correct visibilities.

like image 131
wonko realtime Avatar answered Nov 28 '22 00:11

wonko realtime