Color picker in a Ribbon group

13 posts, 2 answers
  1. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 29 Mar 2011 Link to this post

    Hi,

    I am trying to find a way to add a color picker to a ribbon group. I couldn't find the color picker control as such.
    Could someone help me in this regard?

    I am using RadControls for WinForms Q3 2010.


  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    Hello Jack,

    As far as I'm aware, there is no colour picker as per the one in your screenshot. However, if you go to the demos n your PC and look at the RibbonBar >> First Look one, then there is an exmaple of showing a colour pallette with an Edit Colours section that launches the RadColorDialog. This RadColorDialog can also be seen in full in the demos under Forms & Dialogs >> Color Dialog

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 31 Mar 2011 Link to this post

    Hi Richard,

    Thanks for the reply but I was looking for something similar to the one in MS word. I did look at the color dialog in the examples but will use it in the worst case scenario.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    Hi Jack,

    There is one that someone has created here but this is not supported in any way by Telerik.
    Hope that helps
    Richard
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    Hi,

    I've got a couple of ideas, but not sure if it will work. I'll let you know if I can get something working for you.
    Richard
  7. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    Hi again Jack,

    Ok, I've managed to put something together for you. It's not exactly like the Microsoft one, but it seems to do the job pretty well.
    The concept is based on an inherited RadSplitButton, and then adding in a Menu Item that contains a panel. In the panel I have added the standard RadColorDialogForm and then resized everything to make it look a little neater.

    The new RadDropDownColorPicker looks like a standard RadSplitButton and you can add an image of course to the button to make it look more like you need to. I have made a small video of the functionality which you can find here

    The code probably needs a bit of a tidy up, but it's all here

    RadDropDownColorPicker.vb
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls
      
    Public Class RadDropDownColorPicker
        Inherits RadSplitButton
      
        Private m_CurrentColor As System.Drawing.Color = Color.Black
        Private m_Form As RadColorDialogForm
        Private m_Panel As RadPanel
      
        Public Event ColorChanged As EventHandler(Of ColorChangedEventArgs)
      
      
        Public Sub New()
            MyBase.New()
      
            Me.DropDownButtonElement.ArrowButton.Fill.BackColor = m_CurrentColor
            Me.DropDownButtonElement.ArrowButton.Fill.NumberOfColors = 1
      
            m_Panel = New RadPanel()
      
            Dim item As New RadMenuItem()
            item.MaxSize = New Size(508, 395)
            Me.Items.Add(item)
      
            AddHandler Me.DropDownButtonElement.DropDownMenu.PopupOpened, AddressOf DropDown_PopUpOpened
        End Sub
      
        Public Property CurrentColor As System.Drawing.Color
            Get
                Return m_CurrentColor
            End Get
            Set(value As System.Drawing.Color)
                m_CurrentColor = value
                Me.DropDownButtonElement.ArrowButton.Fill.BackColor = m_CurrentColor
                RaiseEvent ColorChanged(Me, New ColorChangedEventArgs(m_CurrentColor))
            End Set
        End Property
      
      
        Private Sub DropDown_PopUpOpened(sender As Object, args As EventArgs)
            Me.DropDownButtonElement.DropDownMenu.PopupElement.MaxSize = New Size(508, 395)
      
            Me.Items.Clear()
            m_Panel.Size = New Size(508, 395)
            m_Form = New RadColorDialogForm()
            m_Form.SelectedColor = m_CurrentColor
            m_Form.OldColor = m_CurrentColor
            m_Form.ShowBasicColors = False
            m_Form.ShowSystemColors = False
            m_Form.ShowWebColors = False
            m_Form.TopLevel = False
      
            AddHandler m_Form.FormClosing, AddressOf ColorForm_Closing
      
            m_Form.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            m_Panel.Controls.Add(m_Form)
            m_Form.Show()
      
            Dim item As New RadMenuItem()
            item.AutoSize = False
            item.BackColor = Color.Transparent
            item.Size = m_Panel.Size
            item.Alignment = ContentAlignment.MiddleCenter
            item.Children.Add(New RadHostItem(m_Panel))
            Me.Items.Add(item)
      
        End Sub
      
        Private Sub ColorForm_Closing(sender As Object, e As FormClosingEventArgs)
            CurrentColor = CType(sender, RadColorDialogForm).SelectedColor
            Me.DropDownButtonElement.DropDownMenu.ClosePopup(RadPopupCloseReason.ParentClosed)
            Me.DropDownButtonElement.ArrowButton.Fill.BackColor = m_CurrentColor
            RemoveHandler m_Form.FormClosing, AddressOf ColorForm_Closing
        End Sub
      
        Public Overrides Property ThemeClassName As String
            Get
                Return GetType(RadSplitButton).FullName
            End Get
            Set(value As String)
            End Set
        End Property
      
      
      
    End Class

    Example Usage (Form1.vb)
    Imports Telerik.WinControls
    Imports Telerik.WinControls.UI
      
    Public Class Form1
      
        Private Sub RadDropDownColorPicker1_ColorChanged(sender As System.Object, e As Telerik.WinControls.ColorChangedEventArgs) Handles RadDropDownColorPicker1.ColorChanged
            Me.RadLabel1.ForeColor = e.SelectedColor
        End Sub
      
    End Class

    I hope this helps. If you find it good enough, then I might submit it as a Code Library project in both VB and C#.
    Regards,
    Richard

  8. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 31 Mar 2011 Link to this post

    Hi Richard,

    Sorry for the delayed response. I am in the process of testing it out. Will update you asap.

    Thanks a lot for your help.
  9. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    You're welcome Jack. Look forward to hearing back from you
    Richard
  10. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 31 Mar 2011 Link to this post

    Hi Richard,

    Thank you. It worked like a charm. I added the control to a form and was able to use it but looks like a ribbon group can allow only buttonelements and not buttons as such. So, I was not able to add this control to the ribbongroup which is where I actually want to add.

    I tried to make some changes to your code by inheriting from the RadSplitButtonElement but was not successful in handling the DropDownButtonElement property. I couldn't find this property in the RadSplitButtonElement class.

    Please advise me in this regard.
  11. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 31 Mar 2011 Link to this post

    Hi Richard,

    Just read about the button element which I think I should have done much earlier. But anyways, as I understand the RadSplitButtonElement is itself the DropDownButtonElement and I can access the ArrowButton, DropDownMenu etc properties in it.
    Was not able to access these properties earlier for some reason, so was a bit confused.

    Everything just works perfectly as I was able to add the RadDropDownColorPicker to the ribbon group.

    Thanks again.

  12. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Mar 2011 Link to this post

    You're welcome Jack. I'm glad that this helped you out.
    All the best
    Richard
  13. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Apr 2011 Link to this post

    Hello Jack,

    Just to let you know there is a slightly improved version in both C# and VB now available in this code library article
    All the best
    Richard
  14. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 04 Apr 2011 Link to this post

    Thanks Richard.
Back to Top
UI for WinForms is Visual Studio 2017 Ready