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

Changing border color of textbox and have it stay even when control is not in focus

1 Answer 2904 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
LT
Top achievements
Rank 1
LT asked on 11 Aug 2020, 08:29 PM

Hello,

Already using back color of textbox for validation. I'm trying to set border color for a different flag on the same textbox, but this coloring goes back to default color when the control is not in focus using TextBoxElement.Border.ForeColor. Would like to have the backcolor stay all the time; which I could achieve with RootElement.BackColor, but this goes away when the control is in focus.

 

How can I achieve a static border color?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Aug 2020, 08:59 AM

Hello, LT Nguyen,

If I understand your requirement correctly, you are trying to apply a specific border color for RadTextBox no matter  whether the control is focused or not.

Please refer to the following code snippet demonstrating how to achieve it:

        public RadForm1()
        {
            InitializeComponent();  

            this.radTextBox1.BackColor = Color.Yellow;
            this.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red;
        }

The below screenshot illustrates that the border is preserved even though when the second RadTextBox is focused.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
commented on 05 Apr 2022, 12:29 PM

Hi,

I don't know why, but setting forecolor of border (or borderprimitive) affects only border when the control is focused.

See attached screenshots

 

Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
commented on 05 Apr 2022, 01:40 PM

I found that this behavior depends on the chosen theme. in fact, by choosing the visualstudio2022light theme the problem does not arise and I can give a color to the border even when the control has no focus.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 06 Apr 2022, 07:55 AM

Hello, Alessandro,

According to the provided screenshots, it seems that you are using the Fluent theme in your application. Please have in mind that the different themes have different style settings applied to the respective control for the different element states, e.g. mouse over, focused, etc. That is why the BorderPrimitive may not be visible in certain themes. 

The possible solution that I can suggest is to ensure that the BorderBoxStyle.SingleBorder is always used in the different element states for the BorderPrimitive
            ThemeResolutionService.ApplicationThemeName = "Fluent";

            this.radTextBox1.BackColor = Color.Yellow;

            this.radTextBox1.TextBoxElement.Border.Visibility = ElementVisibility.Visible;
            this.radTextBox1.TextBoxElement.Border.BoxStyle = BorderBoxStyle.SingleBorder;
            this.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red;

Tags
TextBox
Asked by
LT
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or