Telerik,如何在RadForm TitleBar中正确添加RadButtonElement?

时间:2014-09-03 03:05:46

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

我试图在标题栏中添加一个按钮,我想给它提供与其他按钮相同的方面,但我无法做到,请参阅:

enter image description here

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

这是我正在使用的代码:

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

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

  

更新

也许某个解决方案可能会在RadForm上应用RadButtonElement的相同主题?

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

...但我真的不明白该怎么做,我没有任何' DefaultStyleBuilder'而且我无法在telerik中找到关于这意味着什么的信息。

2 个答案:

答案 0 :(得分:2)

+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

答案 1 :(得分:0)

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

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

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

enter image description here

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