如何检测控件何时不再可见?
在我当前的应用程序中,我在 TabControl 的页面上有一个 Tree 控件,该控件位于 SplitContainer 控件的面板内。因此,可以通过隐藏 SplitContainer 面板或切换到 TabControl 中的另一个 TabPage 来隐藏树控件。
在表单的菜单中,有一些命令作用于树中当前选定的节点。当用户看不到所选内容时,我不希望启用这些选项。
有没有一种简单的方法可以确定 TreeView 何时退出视图,而无需分别订阅 TabControl 和 SplitContainer 的事件?
In my current app I have a Tree control on a page of a TabControl which is inside a panel of a SplitContainer control. The tree control can thus be hidden by either hiding the SplitContainer panel, or switching to another TabPage in the TabControl.
In the Form's menus there are commands which act on the currently selected Node in the tree. I do not want these options to be enabled when the user can not see what is selected.
Is there a simple way of determining when the TreeView goes out of view with out subscribing to the events of both the TabControl and the SplitContainer separately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建一个布尔成员变量。在 tabchanged 事件中,测试是否选择了树视图选项卡并适当地设置变量。另外,订阅当分割器视图大小更改时触发的事件。测试分割器的宽度或高度,看看您的树视图是否被隐藏。如果是,则将此处的变量设置为。然后您需要做的就是测试您的新成员变量。
You can create a boolean member variable. In the tabchanged event, test to see if the treeview tab is selected and set the variable appropriately. Also, subscribe to the event that is fired when the splitter view size is changed. Test the width or height of the splitter to see if your treeview is hidden. If it is, set the variable here to. Then all you need to do is test your new member variable.
测试 TreeView 的 Visible 属性。还有一个 VisibleChanged 事件。
Test the TreeView's Visible property. There is also a VisibleChanged event.
或者
或者,更好的选择可能是在代码中向 VisibleChanged 事件添加处理程序(或使用设计器视图中的“事件”选项卡):
or
Or, probably the better option would be to add a handler to the VisibleChanged event, in the code (or using the Events tab in Designer view):