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
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
Thanks Dimitar
That works when setting the BackColor of the control. What about setting the Font's color?
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
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
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 ?
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