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

Different BorderColor while Focused

7 Answers 728 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Alwin
Top achievements
Rank 1
Alwin asked on 19 Nov 2009, 01:05 PM
Hi guys,

we want to highlight the currently focused TextBox/MaskedEditBox/ComboBox/MultiColumnCombo, so i thought to use a different BorderColor, but i couldn't find the correct condition... i tried to use this condition: "Telerik.WinControls.RadElement.IsFocused" to set a different BorderColor on the BorderPrimitive, but i think this condition can't be reached because the border never got focus...
Could you please tell me how to set a different ForeColor to the BorderPrimitive when the TextBoxItem GotFocus?

Thank you

Alwin

7 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 25 Nov 2009, 02:54 PM
Hi Alwin,

Currently, the only option for you is to set a custom border color programmatically. I am attaching a sample project to demonstrate this approach.

We will consider supporting the desired behavior by themes in one of our next versions.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sateesh
Top achievements
Rank 1
answered on 02 May 2018, 01:12 PM

Of course this is very old post.

Do you have any elegant solution now to change border  color of text box in focus?

Thanks.

0
Dimitar
Telerik team
answered on 03 May 2018, 11:12 AM
Hi Sateesh,

Now you can change the border color with the following code:
public RadForm1()
{
    InitializeComponent();
    radTextBox1.Enter += RadTextBox1_Enter;
    radTextBox1.Leave += RadTextBox1_Leave;
     
}
private void RadTextBox1_Leave(object sender, EventArgs e)
{
    radTextBox1.TextBoxElement.Border.ForeColor = Color.FromArgb(156, 189, 232);
     
}
private void RadTextBox1_Enter(object sender, EventArgs e)
{
    radTextBox1.TextBoxElement.Border.ForeColor =  Color.Red;
}

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

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Danny
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 12 Aug 2019, 04:50 PM
Hello How would you do it, if you change the border to red, and then return it to normal (RadTextBox.TextBoxElement.Border.ForeColor), regardless of the subject you are in, in my case I am in the Crystal theme, change the color of the border to red becomes super simple, but returning it to normal as the theme applies is complicated, some guide please. note: use vb.net
0
Nadya | Tech Support Engineer
Telerik team
answered on 13 Aug 2019, 11:44 AM
Hello, Danny,

According to your description, I suppose that you want to change the border's ForeColor property of RadTextBox to red color when some condition is met and to reset the color to its default theme color when the condition is not met. To achieve this you should store the default border color in the Load event of the form which occurs before the form is displayed for the first time and ensure that the theme settings are already applied. As it is not specified in your description which element state you want to use, I prepare a sample example by using the element focus state. The example demonstrates how to change the border color when RadTextBox receives focus and how to reset the border color to its default theme color when the focus is lost:

Class SurroundingClass
    Private Sub RadForm1_Load(ByVal sender As Object, ByVal e As EventArgs)
        defaultBorderColor = Me.radTextBox1.TextBoxElement.Border.ForeColor
    End Sub
 
    Private defaultBorderColor As Color
 
    Private Sub RadTextBox1_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
        Me.radTextBox1.TextBoxElement.Border.ForeColor = defaultBorderColor
    End Sub
 
    Private Sub RadTextBox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs)
        Me.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red
    End Sub
End Class

Another approach I can suggest is to make use of the SetThemeValueOverride method and override the ForeColorProperty for a specific element state without losing the applied style for the rest of the states:

Me.radTextBox1.TextBoxElement.SetThemeValueOverride(Telerik.WinControls.Primitives.BorderPrimitive.ForeColorProperty, Color.Red, "ContainsFocus", typeof(Telerik.WinControls.Primitives.BorderPrimitive));

Feel free to use this approach which suits your requirements best. The achieved result is demonstrated in the attached gif file.

I hope this helps. Should you have any other questions, I will be glad to help.

Regards,
Nadya
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
Danny
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 14 Aug 2019, 02:20 PM
perfect works but in the Dema by Default, but that pqasa in the Crystal themes, there is this does not work, the edge does not return to normal, it is altered
0
Nadya | Tech Support Engineer
Telerik team
answered on 15 Aug 2019, 12:43 PM
Hello, Danny,

According to the provided information, it is not clear enough what is the exact requirement that you are trying to achieve. I suppose that you use the Crystal theme for your application and when you change the border color of the TextBoxElement you receive double colored border over it, as shown in the following picture:

 
 
  
 
 
 
 
 


To prevent this, it is necessary to set the TextBoxElement.Border.GradientStyle property to Solid in the GetFocus event:

Private Sub RadTextBox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs)
    Me.radTextBox1.TextBoxElement.Border.ForeColor = Color.Red
    Me.radTextBox1.TextBoxElement.Border.GradientStyle = GradientStyles.Solid
End Sub

I suppose this is what you are looking for. If it doesn't, it would be greatly appreciated if you can provide additional information about the exact goal that you want to achieve. 

I am looking forward to your reply.

Regards,
Nadya
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.
Tags
TextBox
Asked by
Alwin
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Sateesh
Top achievements
Rank 1
Dimitar
Telerik team
Danny
Top achievements
Rank 1
Iron
Veteran
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or