【问题标题】:Telerik, How to properly add a RadButtonElement in a RadForm TitleBar?Telerik,如何在 RadForm TitleBar 中正确添加 RadButtonElement?
【发布时间】:2014-10-27 10:33:39
【问题描述】:

我正在尝试在标题栏中添加一个按钮,我想赋予它与其他按钮相同的外观,但我无法做到,请参阅:

请注意,我的新按钮颜色比其他按钮更亮,而且尺寸突出了黄色边框。

这是我正在使用的代码:

Imports Telerik.WinControls.UI

Public Class RadForm_TestForm : Inherits RadForm

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Set the RadForm design.
    With Me

        .ThemeName = "VisualStudio2012Dark" ' The visual theme.
        .FormElement.Border.ForeColor = Color.Gold   ' Set the borders color.
        .FormElement.Border.Width = 1I ' Set the borders width.
        .FormElement.TitleBar.BorderPrimitive.ForeColor = Color.Red
        .FormElement.TitleBar.ForeColor = Color.LightGray ' Set the TitleBar text color.
        .FormElement.TitleBar.MinimizeButton.Enabled = False

    End With

    ' Create a RadButtonElement.
    Dim SystrayButton As New RadButtonElement()
    With SystrayButton ' Set the RadForm design.

        .Text = "."
        .ShowBorder = False
        .AutoSize = False

        .Size = Me.FormElement.TitleBar.MinimizeButton.Size
        '  .ButtonFillElement.BackColor = Me.FormElement.TitleBar.MinimizeButton.BackColor

    End With

    ' Add the Button in the TitleBar.
    Me.FormElement.TitleBar.Children(2).Children(0).Children.Insert(0, SystrayButton)

End Sub

End Class

请注意,在上面的代码中,这一行被禁用:

.ButtonFillElement.BackColor = Me.FormElement.TitleBar.MinimizeButton.BackColor

因为如果我以这种方式更改颜色,如果我将鼠标放在按钮上,它在聚焦时不会改变颜色。

更新:

也许解决方案可以在RadButtonElement 上应用我的RadForm 的相同主题?

我读过这个:http://www.telerik.com/forums/apply-theme-to-radbuttonelement

...但我真的不明白该怎么做,我没有任何“DefaultStyleBuilder”,我在 Telerik 中找不到关于这意味着什么的信息。

【问题讨论】:

标签: .net vb.net winforms user-controls telerik


【解决方案1】:

+1 我看到了难题。

如果您想在标题栏中显示按钮的悬停、按下和正常状态,您需要创建三个图像并将它们应用于鼠标事件,即在 MouseEnter 上应用悬停图像,在 MouseLeave 上应用正常图像和在 MouseDown 上按下图像。

我看到按钮与黄线略微重叠,因此您可能需要使用图像来解决这个问题。

像你说的那样设置 RadButton BackColors 将阻止默认的悬停、按下和正常状态行为。

看起来您做得正确 - 一个细微的变化是使用 TitleBar.SystemButtons 而不是遍历继承的 TitleBar.Children(2).Children(0).Children.

您可以这样做:

RadButtonElement btn = new RadButtonElement();
btn.ShowBorder = false;
btn.Image = Resources.NormalState;
this.FormElement.TitleBar.SystemButtons.Children.Insert(0,btn);

ps 我不认为使用“StyleBuilders”可以让你获得你想要的外观,顺便说一句,这个请求已被建议给 Telerik:http://feedback.telerik.com/Project/154/Feedback/Details/109772-add-helpbutton-at-the-titlebar-of-radform

【讨论】:

  • 感谢您的帮助,但只是为了能够在 Telerik 表单的 Telerik 标题栏上添加一个新的 Telerik 按钮(是的,我想备注 Telerik 单词,因为所有这些都是由Telerik 所以是不正常的,如果最终用户在 Telerik 表单标题栏中添加一个 Telerik 按钮,该按钮的外观与其他按钮的外观不同)我需要深入了解像 photoshop 这样的图像设计知识来为按钮设计 3 个图像?,真的?是的,它很容易绘制一个正方形并用相同的主题颜色填充它,但我的意思是 Telerik UI 旨在用于开发人员,而不是设计师
  • 另外,如果使用 Telerik UI for Winforms 并在标题栏中带有自定义按钮的开发人员想要添加主题选择器以让该应用程序的用户更改 UI 主题会发生什么?...我需要设计 +/- 30 种不同的图像?如果我也改变它,文本的前景色会发生什么?...要设计更多图像?我真的希望我只是对这个问题一无所知,Telerik 提供了一个官方解决方案,例如:“设置此属性以调整按钮的外观,就像标题栏中的其他按钮一样”,因为这不正常。再次感谢您的回答!
  • +50 for you and I made another bounty with hope to find the key to find the key to this question,因为我不能接受像你建议的那样的替代方案,设计很多每个案例的图像只是不专注于软件开发人员,如果我们谈论大量图像,这有点疯狂。谢谢
  • 谢谢!!听 Telerik 有很大的支持,我发现和他们一起提出这个问题让我有很多时间。
  • 我已经在 Telerik 支持部门发送了两封电子邮件,但没有得到答复 :(.
【解决方案2】:

Telerik 论坛管理员建议的解决方案:

FormElement.TitleBar.SystemButtons 集合包含 RadImageButtonElements。为了向标题栏添加新的系统按钮,您应该创建一个 RadImageButtonElement。此外,要获得与最小化按钮相同的设计,您应该将 RadImageButtonElement.ThemeRole 属性设置为“TitleBarMinimizeButton”。然后,将 DisplayStyle 属性更改为 Text。这是一个示例代码sn-p:

Sub New()
    InitializeComponent()

    With Me
        .ThemeName = "VisualStudio2012Dark" ' The visual theme.
        .FormElement.Border.ForeColor = Color.Gold ' Set the borders color.
        .FormElement.Border.Width = 1I ' Set the borders width.
        .FormElement.TitleBar.BorderPrimitive.ForeColor = Color.Red
        .FormElement.TitleBar.ForeColor = Color.LightGray ' Set the TitleBar text color.
        .FormElement.TitleBar.MinimizeButton.Enabled = False
    End With

    ' Create a RadButtonElement.
    Dim systrayButton As New RadImageButtonElement()
    With systrayButton ' Set the RadForm design.
        .ThemeRole = "TitleBarMinimizeButton"
        .Text = "."
        .DisplayStyle = Telerik.WinControls.DisplayStyle.Text
        .ShowBorder = False
        .AutoSize = False
        .Size = Me.FormElement.TitleBar.MinimizeButton.Size
    End With
    AddHandler systrayButton.Click, AddressOf systrayButton_Click
    ' Add the Button in the TitleBar.
    Me.FormElement.TitleBar.SystemButtons.Children.Insert(0, systrayButton)
End Sub

Private Sub systrayButton_Click(sender As Object, e As EventArgs)
    Me.Size = New Size(600, 600)
End Sub

来源:http://www.telerik.com/forums/how-to-properly-add-a-radbuttonelement-in-a-radform-titlebar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2016-08-04
    • 1970-01-01
    • 2015-11-08
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多