非活动控件背景颜色

发布于 2024-08-14 17:20:47 字数 727 浏览 11 评论 0 原文

Windows 上有没有办法检索用作非活动控件(TextBox 等)背景颜色的颜色?或者更好的是,边框颜色也是如此?

这是针对 Windows 窗体的,我在 SystemColors 中找不到任何合适的内容。没有这样的

事例。我有一个文本框,它可能不足以容纳它所容纳的文本,并且它被禁用。禁用后,用户无法滚动查看整个文本,我什至无法显示工具提示 出于显而易见的原因

因此,我现在所做的是将 TextBoxReadOnly 属性设置为 true,这允许我显示工具提示并使控件可滚动。客户现在希望文本框看起来像是被禁用的; ReadOnly 是一个非常令人讨厌的属性,因为它看起来仍然可以编辑。所以我认为在其中添加适当的背景颜色可能足以欺骗大多数用户。我无法使用任意灰度值,因为该表单上还有其他禁用的控件,并且可能会注意到颜色差异。那么有没有办法可以找出禁用的控件是如何呈现的?背景颜色和边框颜色或至少前者应该足够了,但我不想猜测。有问题的平台很可能是 XP 和 Vista,可能有或没有主题。

预计到达时间:忽略。这个问题很愚蠢,对我来说是一个错误,我应该早点发现。单个文本框不遵循灰色背景有点奇怪。

Is there a way on Windows to retrieve the color used as background color for inactive controls (TextBox, etc.)? Or better yet, the border color too?

This is for Windows Forms and I haven't been able to find anything suitable in SystemColors. There is no such thing

Case in point. I have a text box which may not be large enough for the text it holds and it is disabled. When it is disabled the user cannot scroll to view the entire text and I can't even display a tooltip for obvious reasons.

So what I've done now is setting the TextBox's ReadOnly property to true which allows me to display tooltips and have the control scrollable. The client now wants the text box to look like it was disabled; ReadOnly is a pretty nasty property since it still looks like it can be edited. So I thought putting the proper background color in there might be enough to fool most users. I can't use an arbitrary gray value since there are other disabled controls on that form as well and color differences would probably be noted. So is there a way I can find out how a disabled control gets rendered? Background color and border color or at least the former should really be enough here but I'd rather not guess. Platforms in question are most likely XP and Vista both maybe with or without themes.

ETA: Disregard. The question was stupid and an error on my behalf I should have spotted earlier. It was just a little weird that a single TextBox wouldn't adhere to a gray background.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩人痒 2024-08-21 17:20:47

禁用后,文本框具有背景色 SystemColors.Control 和前景色 SystemColors.GrayText

When disabled, the textbox has background color SystemColors.Control and foreground color SystemColors.GrayText.

无悔心 2024-08-21 17:20:47

试试这个:

        treeView1.EnabledChanged += (s, o) =>
            {
                treeView1.BackColor = treeView1.Enabled ? Color.White : SystemColors.Control;
            };

Try this:

        treeView1.EnabledChanged += (s, o) =>
            {
                treeView1.BackColor = treeView1.Enabled ? Color.White : SystemColors.Control;
            };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文