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

RadTextBox BackColor not working?

24 Answers 1155 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Elizabeth
Top achievements
Rank 1
Elizabeth asked on 23 Apr 2009, 12:33 AM
Seems simple enough...I set BackColor Property on a RadTextBox to something other than System.Control, and it appears to make no change.  I can set ForeColor and get the desired change.  What am I missing?  We are using RadControls for WinForms Q3 2008.

Thanks.

24 Answers, 1 is accepted

Sort by
0
David Mills
Top achievements
Rank 1
answered on 23 Apr 2009, 05:34 AM
I am having the same problem.
0
Elizabeth
Top achievements
Rank 1
answered on 23 Apr 2009, 04:25 PM
Crazy that it takes 5 steps...oh well.

Thanks for contacting us. In order to change the BackColor of the RadTextBox you should use the Edit UI Elements dialog which you can open from the Smart Tag of the control while at design time.

Follow these steps in order to achieve the desired appearance:

1. Drop a RadTextBox control on a Form in Visual Studio.

2. Select the control and open its Smart Tag.

3. Open the Edit UI Elements dialog from the Smart Tag.

4. You see the hierarchy of elements that builds the Telerik RadTextBox control. Select the RadTextBoxItem node from the tree on the left and change its BackColor from the Property Grid on the right.

5. Select the FillPrimitive element from the tree on the left and change its BackColor property again from the grid on the right. You should note that the GradientStyle property of the FillPrimitive should be set to Solid
0
David Mills
Top achievements
Rank 1
answered on 23 Apr 2009, 08:07 PM
I know...Here are is how I got it to work in VB...


 

DirectCast(AM_RadTextBox_AM_Process.TextBoxElement.Children(1), FillPrimitive).BackColor = Color.Linen

 

 

DirectCast(AM_RadTextBox_AM_Process.GetChildAt(0).GetChildAt(0), RadTextBoxItem).BackColor = Color.Linen

 

0
Deyan
Telerik team
answered on 24 Apr 2009, 02:14 PM
Hello Elizabeth and David,

Basically, the BackColor property that comes with the RadTextBox control is inherited from the base Control class that is part of the .NET Framework. By setting this property you change the background color of the control that serves as a surface for our RadTextBox to paint itself. As you may know, the Telerik controls are built upon the Telerik Presentation Framework which is very similar to the WPF architecture, i. e. the controls are built from primitives like FillPrimitive, BorderPrimitive, TextPrimitive etc. This enables the more flexible customization of the appearance of our product. The primitive hierarchy of the RadTextBox is painted upon the surface control and thus you cannot see the result of setting the BackColor property. This implementation enables the user to customize the RadTextBox by separately defining border properties, back color properties and text properties (by modifying the corresponding primitives) and thus creating stylish GUIs built from gradients, alpha blending and transformations.

However, the RadTextBox control is slightly different since it also uses the standard Windows Forms TextBox control, i.e. it wraps its functionality. Therefore, in order to set the background color of the RadTextBox control, you have to separately set the color for the FillPrimitive and the RadTextBoxItem (which is actually the standard text box control) and thus achieving the effect of defining a background color for the whole control. You can do this by using the Element Hierarchy Editor.

I hope this clarifies the reason why setting the BackColor property will not produce the expected result.

Regards,
Deyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
TwoLaJit
Top achievements
Rank 2
answered on 10 Jun 2009, 05:23 AM
This makes sense, I was wondering about this. This confirms it.
0
Frank
Top achievements
Rank 1
answered on 14 Oct 2011, 07:36 PM
I've played with this for a while and I cannot set the full background color (or foreground) of a radTextBox using code

This line below will set an inner border to the indicated color - but I can't figure out the object hierarchy to get to the inner textBox so I can set either the background or foreground color

radTextBox1.TextBoxElement.Fill.BackColor = Color.Yellow;

Could you supply a C# sample to change the foreground and background color for a radTextBox
0
Nikolay
Telerik team
answered on 17 Oct 2011, 04:54 PM
Hi Frank,

In order to change the color of the text box part, you should add one more line to the line that you have found:

this.radTextBox1.TextBoxElement.TextBoxItem.BackColor = Color.Yellow;
this.radTextBox1.TextBoxElement.TextBoxItem.ForeColor = Color.Red;

In order to change the color of the border, you have to access the Border object:
this.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red;

As to the color of the text, you can changed it as shown below:
this.radTextBox1.TextBoxElement.TextBoxItem.ForeColor = Color.Red;

In case you have doubts about the hierarchy of a RadControl, you can use our RadControlSpy tool which will help you in this task.

I hope this helps.

Regards,
Nikolay
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Frank
Top achievements
Rank 1
answered on 17 Oct 2011, 08:56 PM
Thanks - and I'll try out radcontrolspy.
0
Fabian Raul Jofre
Top achievements
Rank 2
answered on 10 Apr 2013, 08:53 PM
this.radTextBox1.TextBoxElement.Border.ForeColor works only for the external border line, im still having a blank space in the control, even if i set the this.radTextBox1.TextBoxElement.Border.BackColor property.

Regards!
0
Stefan
Telerik team
answered on 16 Apr 2013, 08:06 AM
Hi Fabian,

This would probably be the FillPrimitive of RadTextBoxElement. Here is the code needed to change the backcolor of the control to yellow, the border to red and the text to blue:
this.radTextBox1.TextBoxElement.Fill.BackColor = Color.Yellow;
this.radTextBox1.TextBoxElement.TextBoxItem.BackColor = Color.Yellow;
this.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red;
this.radTextBox1.TextBoxElement.TextBoxItem.ForeColor = Color.Blue;

I hope this helps.
 
Greetings,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Sean
Top achievements
Rank 2
answered on 20 Nov 2013, 06:24 AM
how you do this same client side(JavaScript)?
0
Stefan
Telerik team
answered on 20 Nov 2013, 12:00 PM
Hi Sean,

This forum concerns RadControls for WinForms, while your question seems to be related to RadControls for ASP.NET AJAX. Please address your question in the appropriate forum in order to get adequate assistance: http://www.telerik.com/community/forums/aspnet-ajax.aspx.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Ke
Top achievements
Rank 1
answered on 10 Mar 2016, 04:25 AM

I still don't understand the differences between fill primitives and textboxitems.backcolor

They seem to do the same job: set Radcontrol's background color. Why are there both anyway? 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Mar 2016, 01:22 PM
Hello ,

Thank you for writing.

The Telerik Presentation Framework (TPF) offers WPF-like features within classic Windows Forms applications. Note that a control is built up from a few simple types of elements. By working with these elements, you can customize any control on a very granular level.

In Q1 2016 SP1 (version 2016.1.216) we introduced some improvements of the Telerik Presentation Framework and now setting the RadTextBox.BackColor will apply the desired color without the necessity to specify the color for the inner elements:
this.radTextBox1.BackColor = Color.Red;

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Eddy Valson
Top achievements
Rank 2
answered on 23 Jan 2017, 03:26 PM

Here is how to add backcolor to radtextbox server-side, i mean within the tag itself.

 <telerik:RadTextBox ID="txtAudit1" EnabledStyle-BackColor="Black" runat="server" Width="100%" CssClass="text_alignment_right" InputType="Number" ReadOnly="true">

Use the :  EnabledStyle-BackColor="Black"

That's it.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jan 2017, 09:35 AM
Hello Eddy ,

Thank you for writing.  

I would like to note that this forum is relevant for the Telerik UI for WinForms suite. Feel free to post your questions/replies regarding other products in the relevant forum: http://www.telerik.com/forums

Thank you for your understanding.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 21 Jun 2017, 03:49 PM

Hi.  I'm trying to set focus color on a RadTextBoxControl.

I use radTextBoxControl.TextBoxElement.FocusBorderColor = Color.Red;

When textbox is clicked into, nothing happens.  Setting BorderColor does work.  Any help?  Thanks.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jun 2017, 10:26 AM
Hello Michael, 

Thank you for writing.  

In order to use the TextBoxElement.FocusBorderColor it is necessary to set the EnableFocusBorderproperty to true
this.radTextBoxControl1.TextBoxElement.FocusBorderColor = Color.Blue;
this.radTextBoxControl1.TextBoxElement.EnableFocusBorder = true;

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 23 Jun 2017, 01:43 PM
That started working but i only get a border on the bottom of the textboxcontrol.  See attached file.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jun 2017, 08:47 AM
Hello Michael, 

Thank you for writing back. 
 
Indeed, only a bottom border is displayed as it is demonstrated in the referred help article: http://docs.telerik.com/devtools/winforms/telerik-presentation-framework/focus-border-and-ripple-animations.  This is by design.

If you need a border around the entire control you can subscribe to the GotFocus event and change the border color, width and box style: 
public Form1()
{
    InitializeComponent();
 
    this.radTextBoxControl1.GotFocus += radTextBoxControl1_GotFocus;
    this.radTextBoxControl1.LostFocus += radTextBoxControl1_LostFocus;
}
 
Color defaultBorderColor;
 
private void radTextBoxControl1_LostFocus(object sender, EventArgs e)
{
    this.radTextBoxControl1.TextBoxElement.BorderColor = defaultBorderColor ;
}
 
private void radTextBoxControl1_GotFocus(object sender, EventArgs e)
{
    this.radTextBoxControl1.TextBoxElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.SingleBorder;
    defaultBorderColor = this.radTextBoxControl1.TextBoxElement.BorderColor;
    this.radTextBoxControl1.TextBoxElement.BorderColor = Color.Red ;
    this.radTextBoxControl1.TextBoxElement.BorderWidth = 1;
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 27 Jun 2017, 06:06 PM
Its sort of working but still doesn't look right.  You can see the orange of the typical color still and the bottom border is still thick (I tried setting textBox_Find.TextBoxElement.BorderWidth = 1;  but had no effect).  If Iturn off the EnableFocusBorder from the previous post then you see orange on the bottom that gradients to red at the top.  I don't understand why this isn't simpler.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Jun 2017, 12:19 PM
Hello Michael, 

Thank you for writing back. 

Please refer to the attached sample project which result is illustrated in the attached gif file. If it is still not the desired look, it would be greatly appreciated if you can provide a screenshot of the exact goal that you are trying to achieve. Thus, we would be able to think about a suitable solution and assist you further. Thank you in advance.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 29 Jun 2017, 01:20 PM
Thanks.  I got it now.  Part of the problem was that i was applying a theme to the entire form with ThemeResolutionService.ApplicationThemeName = "Office2010Silver";
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jul 2017, 10:16 AM
Hello Michael, 

Thank you for writing back. 

If you apply the Office2010Silver theme to the entire application it is necessary to set the TextBoxElement.BorderGradientStyle property to Solid in addition to the previously provided code snippet:
private void radTextBoxControl1_GotFocus(object sender, EventArgs e)
{
    this.radTextBoxControl1.TextBoxElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.SingleBorder;
    defaultBorderColor = this.radTextBoxControl1.TextBoxElement.BorderColor;
    this.radTextBoxControl1.TextBoxElement.BorderColor = Color.Red ;
    this.radTextBoxControl1.TextBoxElement.BorderGradientStyle = GradientStyles.Solid;
    this.radTextBoxControl1.TextBoxElement.BorderWidth = 1;
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TextBox
Asked by
Elizabeth
Top achievements
Rank 1
Answers by
David Mills
Top achievements
Rank 1
Elizabeth
Top achievements
Rank 1
Deyan
Telerik team
TwoLaJit
Top achievements
Rank 2
Frank
Top achievements
Rank 1
Nikolay
Telerik team
Fabian Raul Jofre
Top achievements
Rank 2
Stefan
Telerik team
Sean
Top achievements
Rank 2
Ke
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Eddy Valson
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or