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

Multiline RadTextbox - changing backcolor when disabled

7 Answers 319 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Eric Moreau asked on 12 Apr 2019, 02:11 PM

Hi

I have been using the code from https://www.telerik.com/support/kb/winforms/editors/details/changing-the-text-color-of-a-disabled-radtextbox for years now with success until I discovered that it doesn't work well with MultiLine textboxes.

Is there another way (I am using the latest bits) to achieve that behavior (changing the backcolor of disabled control) that would work with multiline textboxes?

7 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Apr 2019, 06:13 AM
Hello Eric,

This is an old solution and now there is a simpler way to achieve this. You can change the color in the theme either in Visual Style Builder or in the code. For example: 
radTextBox1.TextBoxElement.SetThemeValueOverride(RadItem.BackColorProperty, Color.Red, "Disabled");

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Apr 2019, 12:42 PM

Thanks Dimitar

That works when setting the BackColor of the control. What about setting the Font's color?

0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Apr 2019, 05:46 PM

Hi 

Just to be 100% clear, what I am trying to achieve is to set the color of the text in a radtextbox when this one is disabled.

I have been able to do it using similar to the one from the old article. But I found out that this code has an issue with MultiLine textboxes (all merged into a single line).

Thanks

0
Dimitar
Telerik team
answered on 17 Apr 2019, 08:22 AM
Hi Eric,

I have examined the solution in the article. It adds additional textbox over the default one and changes its visibility when the control is enabled/disabled. However, the Multiline property will not affect the second textbox and this is why you do not see the entire text. You need to set the Multiline property of the second text box as well:
public class MyRadTextBox : RadTextBox
{
    MyTextBox mtb = new MyTextBox();
    RadTextBoxItem tbi;
 
    protected override void CreateChildItems(Telerik.WinControls.RadElement parent)
    {
        base.CreateChildItems(parent);
 
        tbi = new RadTextBoxItem(mtb);
        tbi.Multiline = true;
 
        mtb.Font = this.Font;
        this.TextBoxElement.Children.Add(tbi);
 
    }
 
    protected override void OnEnabledChanged(EventArgs e)
    {
        if (!this.Enabled)
        {
            tbi.Text = this.Text;
            this.TextBoxElement.TextBoxItem.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
        else
        {
            this.TextBoxElement.TextBoxItem.Visibility = Telerik.WinControls.ElementVisibility.Visible;
        }
 
        base.OnEnabledChanged(e);
    }
 
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadTextBox).FullName;
        }
    }
 
}
 
I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 17 Apr 2019, 12:47 PM

Good catch Dimitar.

Meanwhile, I also found your new RadTextBoxControl which seems to support these behaviors without too many workarounds.

Should I consider moving to RadTextBoxControl ?

0
Accepted
Dimitar
Telerik team
answered on 18 Apr 2019, 06:33 AM
Hello Eric,

Yes, if you do not need RightToLeft support consider using RadTextBoxControl. You will only need to set the following properties to enable the custom disabled ForeColor:
radTextBoxControl1.RootElement.UseDefaultDisabledPaint = false;
radTextBoxControl1.ForeColor = Color.Red;
 
I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 18 Apr 2019, 01:32 PM
Thanks Dimitar
Tags
TextBox
Asked by
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or