This is a migrated thread and some comments may be shown as answers.

RadLabel Disable state forecolor issue

4 Answers 337 Views
Label
This is a migrated thread and some comments may be shown as answers.
Ke
Top achievements
Rank 1
Ke asked on 16 Mar 2016, 08:14 PM

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
             
        }
    }
     
}

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 17 Mar 2016, 11:42 AM
Hello ,

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.
0
Ke
Top achievements
Rank 1
answered on 18 Mar 2016, 05:40 PM

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. 

0
Ke
Top achievements
Rank 1
answered on 18 Mar 2016, 07:13 PM

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

0
Dimitar
Telerik team
answered on 21 Mar 2016, 09:39 AM
Hello ,

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.
Tags
Label
Asked by
Ke
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Ke
Top achievements
Rank 1
Share this question
or