RadMaskedEdit Backcolor to Control

3 posts, 1 answers
  1. Scott
    Scott avatar
    6 posts
    Member since:
    Nov 2010

    Posted 03 Nov 2010 Link to this post

    I want to change the backcolor of a maskedit control to SystemColors.Control

    I do not want to use themes at all.
    I found some sample code and it works with all colors except for SystemColors.Control.

    To prove this I just blended the Control backcolor slightly and it works correctly then.
    This is not a critical issue as I have found a work around but this is quite tricky to do a took me like about an hour to figure it out,
    Changing a controls back color is something that should be simple.
    I was expecting to turn the EnableTheming = False and then just be able to change a textbox.Backcolor property and that is all.
    But I would be happy to have this SystemColors.Control issue fixed.

    Here is some sample code I have made to show the issue,
    I'm using a wrapper class so i can add controls the way i want them to behave with out setting lots of individual properties everytime.

    Public Class RadMaskedEditBoxX
        Inherits Telerik.WinControls.UI.RadMaskedEditBox

        Public Sub New()
            Me.EnableTheming = False
        End Sub

        Protected Overrides Sub OnReadOnlyChanged(ByVal e As System.EventArgs)
            MyBase.OnReadOnlyChanged(e)
            If Me.ReadOnly Then
                SetColor(SystemColors.Control)
            Else
                SetColor(SystemColors.Window)
            End If
        End Sub

        Public Sub SetColor(ByVal clrColor As Color)

            MyBase.MaskedEditBoxElement.Fill.GradientStyle = Telerik.WinControls.GradientStyles.Solid
            MyBase.MaskedEditBoxElement.Fill.BackColor = clrColor
            MyBase.MaskedEditBoxElement.Border.ForeColor = SystemColors.WindowFrame
           
            '--------------------------------------------------------------------
            ' This Line does not work correctly with the Control Color, it does with any other color.
            ' When set to Control it still blends itself with white so is some light grey color 
            '(very hard to tell difference from white (non-readonly) textbox).
            MyBase.MaskedEditBoxElement.BackColor = SystemColors.Control
            ' -------------------------------------------------------------------
            ' This is my fix for this problem, To blend the color so it is not = SystemColors.Control but very close
            'MyBase.MaskedEditBoxElement.BackColor = modShared.BlendColor(SystemColors.Control, Color.White, 1)

        End Sub

        Public Overrides Property ThemeClassName() As String
            Get
                Return GetType(Telerik.WinControls.UI.RadMaskedEditBox).FullName
            End Get
            Set(ByVal value As String)
                MyBase.ThemeClassName = value
            End Set
        End Property

        Public Function BlendColor(ByVal p_Color1 As Color, ByVal p_Color2 As Color, ByVal p_blend As Integer) As Color

            Try

                Dim r As Single, g As Single, b As Single
                Dim dr As Single, dg As Single, db As Single

                dr = (p_Color2.R - p_Color1.R) / 255
                dg = (p_Color2.G - p_Color1.G) / 255
                db = (p_Color2.B - p_Color1.B) / 255

                r = p_Color1.R
                g = p_Color1.G
                b = p_Color1.B

                BlendColor = Color.FromArgb(r + (dr * p_blend), g + (dg * p_blend), b + (db * p_blend))

            Catch

                Try
                    Dim r As Single, g As Single, b As Single
                    Dim dr As Single, dg As Single, db As Single

                    dr = (p_Color1.R - p_Color2.R) / 255
                    dg = (p_Color1.G - p_Color2.G) / 255
                    db = (p_Color1.B - p_Color2.B) / 255

                    r = p_Color2.R
                    g = p_Color2.G
                    b = p_Color2.B

                    BlendColor = Color.FromArgb(r + (dr * p_blend), g + (dg * p_blend), b + (db * p_blend))
                Catch
                    If p_blend < 127 Then
                        BlendColor = p_Color1
                    Else
                        BlendColor = p_Color2
                    End If
                End Try

            End Try

        End Function

    End Class

  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 12 Nov 2010 Link to this post

    Hello Scott,

    Thank you for your code snippet.

    It helped us to understand your case. You can change the color of the internal textbox to Control by changing the BackColor property of the TextBoxItem as it is shown below:
    MyBase.MaskedEditBoxElement.TextBoxItem.BackColor = clrColor

    We will investigate what causes the experienced issue where you set the Control color to the MaskedEditBoxElement and will address it in one of our next releases.

    Your Telerik points have been updated for the feedback. If you have additional questions, feel free to contact me.

    Greetings,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Scott
    Scott avatar
    6 posts
    Member since:
    Nov 2010

    Posted 24 Nov 2010 Link to this post

    Thanks this property did change the backcolor as expected.
    If anyone else is having the same issue this is my working class

    Public Class RadMaskedEditBoxX
        Inherits Telerik.WinControls.UI.RadMaskedEditBox

        Public Sub New()
            Me.EnableTheming = False
            MyBase.MaskedEditBoxElement.Border.ForeColor = SystemColors.WindowFrame
        End Sub

        Protected Overrides Sub OnReadOnlyChanged(ByVal e As System.EventArgs)
            MyBase.OnReadOnlyChanged(e)
            If Me.ReadOnly Then
                SetColor(SystemColors.Control)
            Else
                SetColor(SystemColors.Window)
            End If
        End Sub

        Public Overrides Property BackColor() As System.Drawing.Color
            Get
                Return MyBase.BackColor
            End Get
            Set(ByVal value As System.Drawing.Color)
                MyBase.BackColor = value
                SetColor(value)
            End Set
        End Property

        Public Sub SetColor(ByVal clrColor As Color)

            MyBase.MaskedEditBoxElement.Fill.GradientStyle = Telerik.WinControls.GradientStyles.Solid
            MyBase.MaskedEditBoxElement.Fill.BackColor = clrColor

            MyBase.MaskedEditBoxElement.TextBoxItem.BackColor = clrColor

        End Sub

    End Class

Back to Top