如何禁用 TabControl 内的选项卡? [英] How can I disable a tab inside a TabControl?

查看:36
本文介绍了如何禁用 TabControl 内的选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法禁用 TabControl?

推荐答案

TabPage 类隐藏了 Enabled 属性.这是故意的,因为它存在一个尴尬的 UI 设计问题.基本问题是禁用页面不会同时禁用选项卡.如果尝试通过使用 Selecting 事件禁用选项卡来解决这个问题,那么当 TabControl 只有一页时它不起作用.

The TabPage class hides the Enabled property. That was intentional as there is an awkward UI design problem with it. The basic issue is that disabling the page does not also disable the tab. And if try to work around that by disabling the tab with the Selecting event then it does not work when the TabControl has only one page.

如果这些可用性问题与您无关,那么请记住该属性仍然有效,它只是对 IntelliSense 隐藏了.如果 FUD 不舒服,那么你可以简单地这样做:

If these usability problems do not concern you then keep in mind that the property still works, it is merely hidden from IntelliSense. If the FUD is uncomfortable then you can simply do this:

public static void EnableTab(TabPage page, bool enable) {
    foreach (Control ctl in page.Controls) ctl.Enabled = enable;
}

这篇关于如何禁用 TabControl 内的选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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