RadLabel Disable state forecolor issue

5 posts, 0 answers
  1. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 16 Mar Link to this post

    I have a user control that contains a radlabel and a radmaskedtextbox. I need to change the backcolor of the textbox to match the forecolor of the radlabel when the user control is disabled. Everything works fine if the user control is initially enabled. However, If I set the initial state of the user control disabled, then upon running the program, the maskedtextbox's backcolor is black while the forecolor of the radlabel is gray. Here is the code: 

    Color disableColor;
     
    private void maskedTextBox_EnabledChanged(object sender, EventArgs e)
    {
     
            if (!this.maskedTextBox.Enabled)
            {                 
                //Set disable color the same as the label text color
                this.radLabel.LabelElement.VisualState = "RadLabelElement.Disabled";                   
                disableColor = this.radLabel.LabelElement.ForeColor;
     
                //Change the backcolor of the maskedtextbox
                this.maskedTextBox.MaskedEditBoxElement.TextBoxItem.BackColor = disableColor;
     
            }
            else
            {
                //Reset values
                 
            }
        }
         
    }
  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 17 Mar Link to this post

    Hello Ke,

    Thank you for contacting us.

    You can change the disabled color in the theme. To do that you should open the theme in Visual Style Builder. Then you need to change the back color for the disabled states for RadMaskedEditBox and RadTextBox. I have attached a small sample that demonstrates this. The attached images show which styles I have changed.

    Detailed information about this is available in the following articles:
    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 18 Mar in reply to Dimitar Link to this post

    Can you show me some hints on how to fix this problem at run time, please? I have been getting stuck on this for three days. It seems to me that if the label is set to be disabled at the beginning, and is assigned the above enabled-changed event, when the event is triggered, while loading the form, I am supposed to get the disabled label color, which is gray, using the following code:   

    disableColor = this.radLabel.LabelElement.ForeColor;

    Instead, I am getting black color. During the initializing stage, the label is disabled (enabled = false), but the color is still black. I am curious why this is happening. 

  5. Ke
    Ke avatar
    18 posts
    Member since:
    Feb 2016

    Posted 18 Mar in reply to Dimitar Link to this post

    I feel like this is caused by RadElement Lifecycle. Do you have more information on that? this link below is all that I can find. I need to know how I can implement the lifecycle. Thank you!

    http://www.telerik.com/blogs/radelement-lifecycle-ndash-a-winforms-tpf-story

  6. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 21 Mar Link to this post

    Hello Ke,

    Thank you for writing back.

    To change this color at runtime you should use the SetThemeValueOverride method which changes a theme property for a particular state. For example:
    radTextBox1.TextBoxElement.SetThemeValueOverride(RadItem.BackColorProperty, Color.Red, "Disabled");
    radMaskedEditBox1.MaskedEditBoxElement.SetThemeValueOverride(RadItem.BackColorProperty, Color.Red, "Disabled");

    There is no way to get the color of the disabled state from the theme at a run time. And this is not connected to the element life cycle. Perhaps for your case, you can set the disabled color for both of the controls at runtime. However, please note that when this approach is used you should call the method for each control. If the theme is changed the color will be applied to all controls.

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready