【问题标题】:Telerik, how to preserve a custom colorization when disabling a control?Telerik,禁用控件时如何保留自定义着色?
【发布时间】:2014-10-24 23:17:20
【问题描述】:

我有一个应用了VisualStudio2012Dark 主题的RadSplitButton,我通过Edit UI elements 设计菜单将边框设置为黄色:

问题在于,当我禁用将Enabled 属性设置为False 的控件时,它完全改变了颜色,并且在我的应用程序中引起了非常糟糕的视觉效果:

我可以指定禁用控件时使用什么颜色?

【问题讨论】:

  • 所有禁用的颜色似乎都是预设的,您无法更改。它们似乎是按主题分配的,因此当您修改许多 UI 元素时,您会得到非常糟糕的结果,例如不可见的按钮文本。
  • 您也可以将RadSplitBitton.RootElement.UseDefaultDisabledPaint 设置为false,但它基本上不使用主题,因此控件被绘制为ControlDefault,不知道它已被禁用。
  • 当 UseDefaultDisabledPaint 设置为 false 时,可以定义控件的 Disabled 状态在主题中的外观 - 只需添加 s .Disabled 状态并根据需要设置主题。

标签: c# .net vb.net winforms telerik


【解决方案1】:

正如 Plutonix 在他的评论中所说,禁用的颜色是预设的,但是可以使用 Telerik Style Builder 进行修改(请参阅下面的更新)。另一种方法可能是将控件放在透明面板后面并将其设置为可见或不可见,以使您的 radSplitButton 可访问或不可访问。这种方法显然不会影响控件的颜色。 由于您还使用了 c# 标记,所以我更喜欢在 c# 中将其提供给您:

将此类添加到您的项目中:

class Plexiglass : Control
{
    protected override void OnPaint(PaintEventArgs e)
    {
        if (Parent != null)
        {
            Bitmap plexiCover = new Bitmap(Parent.Width, Parent.Height);
            foreach (Control c in Parent.Controls)
                if (c.Bounds.IntersectsWith(this.Bounds) & c != this)
                    c.DrawToBitmap(plexiCover, c.Bounds);
            e.Graphics.DrawImage(plexiCover, -Left, -Top);
            plexiCover.Dispose();
        }
        e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(128, 0, 0, 0)), Bounds);
    }
}

编译项目,将 Plexiglass 控件从您的工具箱添加到表单中,将其拖到 RadsplitButton 上并调整其大小。然后,您可以在表单加载事件中将 Plexiglass 控件的可见性设置为 false,并管理 Plexiglass 控件的可见性以使您的 splitButton 可访问或不可访问。 Here 是最终结果,here 是演示项目。感谢 IntelOrca 的 sn-p。

更新 或者,您可以探索使用Visual Style Builder 更改预设颜色的可能解决方案。我已经更新了它,但从这个video 看起来你可以更改许多控件颜色和相关行为。您可以通过以下方式访问该工具:“开始菜单(开始 程序 Telerik RadControls for WinForms Qx 201x Tools)”。 在工具中加载 RadSplitButton 后,在元素状态(右上角面板)中添加状态“已禁用”,并对其应用与正常状态相同的颜色。这应该可行,但正如我所说,我从未使用过它,所以我不确定该过程,但是它看起来非常强大,并且可以避免您必须手动处理控件的所有方法和属性。

【讨论】:

  • 我不确定,属性RadSplitButton.DropDownButtonElement.UseDefaultDisabledPaint 说:Gets or sets whether the item should use the default way for painting the item when disabled (making it gray) or whether the disabled appearance should be controlled by the theme. 但我不知道该怎么办,它没有任何效果,我有这样的原因认为这种“禁用自定义”是可能的,但在控件或其子控件上“隐藏”,是太多的属性和方法来一一研究其功能。谢谢你的回答!
  • 我理解你的困境。在 asp 中,您可以覆盖控件 css,但在 winform 中是另一回事,这是我建议的解决方法。祝你好运。
  • 抱歉迟到了,真的是一个很好的技巧。
【解决方案2】:

这是一个替代解决方案,但我找不到更有效的解决方案:

    With Me.RadSplitButton1
        .DropDownButtonElement.ShouldHandleMouseInput = False
        .DropDownButtonElement.ActionButton.ShouldHandleMouseInput = False
        .DropDownButtonElement.ArrowButton.ShouldHandleMouseInput = False
         .Cursor = Cursors.No
    End With

这会禁用控件上的鼠标输入,但只是这样做。它是“半禁用”而不会丢失当前的着色。

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 2017-09-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 2012-10-05
    • 1970-01-01
    • 2010-10-26
    相关资源
    最近更新 更多