Access C1Themes Colors Assigned to a Control

Posted by: gkayne on 13 October 2017, 1:52 pm EST

    • Post Options:
    • Link

    Posted 13 October 2017, 1:52 pm EST

    I am modifying the styles for a C1Flexgrid control I use as a tree view with the code shown below. I want the empty area white and the Focus style’s BackColor to match the Highlight style’s BackColor.

    The Code works, however, I am using C1Themes and this code runs after the ObjectThemeChanged Event is fired. Is there a way to determine and access the colors set by the current theme rather than using SystemColors as shown below?

    <VB.NET Code Snippet>
    
    _C1FlexGridControl.SelectionMode = SelectionModeEnum.Row
        _C1FlexGridControl.HighLight = HighLightEnum.Always
    
    Dim cs As CellStyle
       
    'Empty Area
        cs = _C1FlexGridControl.Styles.EmptyArea
        cs.BackColor = SystemColors.Window
        cs.Border.Style = BorderStyleEnum.None
    
        'Highlight Style
        cs = _C1FlexGridControl.Styles.Highlight
        cs.BackColor = SystemColors.GradientInactiveCaption
        cs.ForeColor = SystemColors.InactiveCaptionText
    
        'Focus Style
        cs = _C1FlexGridControl.Styles.Focus
        cs.BackColor = SystemColors.GradientInactiveCaption
        cs.ForeColor = SystemColors.InactiveCaptionText
    
  • Posted 14 October 2017, 1:11 am EST

    The best place to start is by using the C1ThemeDesigner app and find the path to style color you are looking for and send this path (see the arrow) to one of the functions included below depending on what you are looking for. There are many fonts, colors etc. set by a theme.

    Function

    Public Function getThemeBackgroundColor(path As String, Optional defaultColor As Color = Nothing, Optional theme As C1Theme = Nothing) As Color
        getThemeBackgroundColor = defaultColor
        Dim tbb As ThemeBrushBase = Nothing
        If theme Is Nothing Then theme = getApplicationTheme()
        Dim bg = CStr(theme.GetBackgroundBrushStr(path))
        If bg Is Nothing Then
            Return getThemeColor(path, defaultColor, theme)
        End If
        ThemeBrushBase.TryDecodeFromString(bg, tbb)
        Dim solidBrush = TryCast(tbb, ThemeSolidBrush)
        If solidBrush Is Nothing Then
            Dim sbg = bg.ToString
            Dim sbgs() = sbg.Split(vbCr)
            If sbgs.Count > 0 Then
                Select Case sbgs(0)
                    Case "ThemeTwoColorLinearBrush" 'ThemeTwoColorLinearBrush true 90 255, 187, 0 255, 229, 100 
                        Dim sbgc = sbgs(3).Split(",")
                        getThemeBackgroundColor = Color.FromArgb(255, CInt(sbgc(0)), CInt(sbgc(1)), CInt(sbgc(2)))
                    Case "ThemeMultiColorLinearBrush" 'ThemeMultiColorLinearBrush true 90 0#251, 219, 181;0.3#254, 199, 120;0.301#254, 180, 86;1#253, 235, 159"
                        Dim sbgg = sbgs(3).Split(";")
                        Dim sbc = sbgg(0).Substring(sbgg(0).IndexOf("#") + 1)
                        Dim sbgc = sbc.Split(",")
                        getThemeBackgroundColor = Color.FromArgb(255, CInt(sbgc(0)), CInt(sbgc(1)), CInt(sbgc(2)))
                End Select
            End If
        Else
            getThemeBackgroundColor = solidBrush.Color
        End If
    End Function
    Public Function getThemeBackgroundBrush(path As String, defaultColor As Color, Optional brushRectangle As Rectangle = Nothing, Optional theme As C1Theme = Nothing) As Brush
        Dim tbb As ThemeBrushBase = Nothing
        If theme Is Nothing Then theme = getApplicationTheme()
        Dim bg = theme.GetBackgroundBrushStr(path)
        ThemeBrushBase.TryDecodeFromString(bg, tbb)
        If tbb Is Nothing Then
            defaultColor = getThemeBackgroundColor(path)
            Return New SolidBrush(defaultColor)
        Else
            If brushRectangle.Width = 0 Then
                brushRectangle = New Rectangle(0, 0, 16, 16)
            End If
            Dim brush = tbb.GetBrush(brushRectangle)
            If brush Is Nothing Then
                defaultColor = getThemeBackgroundColor(path)
                brush = New SolidBrush(defaultColor)
            End If
            Return brush
        End If
    End Function
    Public Function getThemeColor(path As String, Optional defaultColor As Color = Nothing, Optional theme As C1Theme = Nothing) As Color
        If theme Is Nothing Then theme = getApplicationTheme()
        getThemeColor = theme.GetColor(path, defaultColor)
        '      Dim x = theme.Children(2).Children(0).Children(0).
    End Function
    Private Function getApplicationTheme() As C1Theme
        Dim theme = C1ThemeController.GetThemeByName(My.Settings.applicationThemenName, False)
        If theme Is Nothing Then
            theme = C1ThemeController.GetThemeByName("Office2010Blue", False)
        End If
        Return theme
    End
    
  • Posted 14 October 2017, 8:03 am EST

    Thanks a bunch for the code - works perfectly.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels