How to properly add a RadButtonElement in a RadForm TitleBar?

4 posts, 2 answers
  1. Christian
    Christian avatar
    12 posts
    Member since:
    Sep 2014

    Posted 13 Sep 2014 Link to this post

    I'm trying to add a button in the Titlebar, I would like to give it the same aspect than the other buttons but I'm unable to do it, see:

    http://i.stack.imgur.com/cH5Zw.png

    Notice that my new button has a shiner color than the others and also the size protrudes out the yellowed border.

    This is the code that I'm using:
    ----------------------------------------------------------------------------------------------------------
    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
    ----------------------------------------------------------------------------------------------------------
    Notice that in the code above this line is disabled:

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

    Because if I change the color in that way, if I put the mouse over the button it does not change the color when it is focused so it replaces the focused state.












    I'm trying to add a button in the Titlebar, I would like to
    give it the same aspect than the other buttons but I'm unable to do it,
    see:



    Notice that my new button has a shiner color than the others and also the size protrudes out the yellowed border.

    This is the code that I'm using:

    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

    Notice that in the code above this line is disabled:

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

    Because if I change the color in that way, if I put the mouse over the button it does not change the color when it is focused.

    Maybe a solution could be applying the same theme of my RadForm on the RadButtonElement?

    I've read this: http://www.telerik.com/forums/apply-theme-to-radbuttonelement

    ...but I really don't understand how to do it, I don't have any 'DefaultStyleBuilder' and I can't find info in telerik about what means that.


    PS: Here you can read this question in other webpage: http://stackoverflow.com/questions/25635610/telerik-how-to-properly-add-a-radbuttonelement-in-a-radform-titlebar/25799876?noredirect=1#comment40391390_25799876

    I need help to solve this... thanks.
  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 17 Sep 2014 Link to this post

    Hello Christian,

    Thank you for writing.

    FormElement.TitleBar.SystemButtons collection contains RadImageButtonElements. In order to add a new system button to the title bar, you should create a RadImageButtonElement. Additionally, to obtain the same design as the Minimize button, you should set the RadImageButtonElement.ThemeRole property to "TitleBarMinimizeButton". Afterwards, change the DisplayStyle property to Text. Here is a sample code snippet:
    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

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Christian
    Christian avatar
    12 posts
    Member since:
    Sep 2014

    Posted 22 Sep 2014 in reply to Dess Link to this post

    @Desislava

    Simply amazing, thankyou!

    I have 2 offtopic questions if you could help me to understand:
    1) After writting my post I noted that I've duplicated some of the code (by error), there is any button to edit my post, right?
    2) I didn't see any help to insert a code properly like you did, there is any post in the forum explaining the tags to use them?

    Thanks for your time.
  5. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 25 Sep 2014 Link to this post

    Hello Christian,

    Thank you for writing back.

    I am glad that the provided solution suits your requirement.

    As to the question related to editing a certain forum post, currently you are not allowed to modify it. The possible solution is to specify the exact modification that you want to perform in a thread post to our support officers and they will update it for you. We have a feature request for adding such functionality to the forums.

    In order to insert formatted code, you should use the "Format Code Block" option. Please refer to the attached screenshot.

    I hope this information helps. If you have any additional questions, please let me know.
     
    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top