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

RadTextBox Mouse Hover to change Backcolor

3 Answers 285 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Ke
Top achievements
Rank 1
Ke asked on 03 Mar 2016, 01:53 AM

I need to achieve a function that when mouse hover over a RadTextBox, it changes its background color. Like what is shown in the demo, text box changed color from gray to white when mouse cursor moves inside the text box.  

I tried to use Mouse-Enter event to change the backcolor. However, this event only triggers when the mouse cursor touches exactly at the border of the text box, as soon as it leaves the border, although the mouse cursor stays inside the text box, this event is no longer valid. I also tried Mouse-hover event, which did not give me a good result either. 

It seems to me that what I need to achieve is a common issue and must have a relatively easy solution. I am wondering if I missed anything.

Thank you! 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 04 Mar 2016, 09:33 AM
Hi ,

Thank you for writing.

You should use the events of the TextBoxItem:
public RadForm1()
{
    InitializeComponent();
    radTextBox1.TextBoxElement.TextBoxItem.MouseEnter += radTextBox1_MouseEnter;
    radTextBox1.TextBoxElement.TextBoxItem.MouseLeave += radTextBox1_MouseLeave;
}
 
void radTextBox1_MouseLeave(object sender, EventArgs e)
{
    radTextBox1.BackColor = Color.White;
}
 
void radTextBox1_MouseEnter(object sender, EventArgs e)
{
     radTextBox1.BackColor = Color.Red;
}

Let me know if you have additional questions.

Regards,
Dimitar
Telerik

0
Ke
Top achievements
Rank 1
answered on 04 Mar 2016, 02:27 PM

Thank you, this answers my question. Just a quick fix to your code. I also need to use the TextBoxItem to change the background color. 

void radTextBox1_MouseLeave(object sender, EventArgs e)
{
    radTextBox1.TextBoxElement.TextBoxItem.BackColor = Color.White;
}

0
Dimitar
Telerik team
answered on 07 Mar 2016, 10:20 AM
Hi Ke,

Thank you for writing back.

In the latest version, you should be able to set the color directly. For  previous versions, you should use the TextBoxItem property.

In addition, I want to mention that you with the latest version you can directly set the Back/Fore color of most controls.

I hope this will be useful. 

Regards,
Dimitar
Telerik

Tags
TextBox
Asked by
Ke
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Ke
Top achievements
Rank 1
Share this question
or