如何检测控件的可见性? [英] How can I detect the visibility of a control?

查看:99
本文介绍了如何检测控件的可见性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测控件是否对用户可见?我有一个控件,用于显示应用程序的状态,并且仅当用户看到它时,我才希望对其进行更新(例如,要更新的值,增加进度条的值或更改标签的Text属性)。如果用户最小化了包含该控件的表单,或者另一个表单与该控件重叠,则无需更新它。如果控件不可见,我只是不想做额外的计算。
另外,如何检测隐藏/显示此控件的事件?

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?

推荐答案

这似乎是其中之一

首先,为了参考起见, some 链接到旧的主题。在研究过程中偶然发现的讨论:

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

开始位置:
一种用于异构系统的IDE许多不同的硬件和许多不同的传输层,其中有些确实很慢。一种功能是在编辑器中显示远程硬件的内存值。典型的用例是打开20个以上的编辑器,每个编辑器显示1至100个不同的值。

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.

(部分)解决方案:
可见性跟踪器,基本上管理用于控件本身和每个祖先控件。适配器处理可视性取决于祖先类型,即。对于控件,它只是实例。可见,对于TabPage,我检查选择了哪个页面,...
然后,经理的客房整理只是跟踪所有祖先的父代更改,以便跟踪正确的信息。可见性。

(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.

这篇关于如何检测控件的可见性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆