Share via


How to make the textbox to highlight in C#

Question

Thursday, September 9, 2010 9:34 AM

Hello All,

I have to highlight the textbox when the user enters the Add button. The textbox is in nextpage In the next page which should be highlighted. I tried textbox1.Focus(). It will only highlight the textbox, but to enter the text in it, user should click the mouse on it. I also tried

System.Windows.Input.Keyboard.Focus(textbox1);

can you please help me to figure out the exact method.

Thx,
Shilpa

All replies (7)

Thursday, September 9, 2010 8:02 PM

textBox1.SelectAll(); with select all text in the textbox. Is that what you want to do?


Sunday, September 12, 2010 1:29 PM

    private void textBox1_MouseEnter(object sender, EventArgs e)
    {
      textBox1.BackColor = System.Drawing.Color.LightYellow;
    }

    private void textBox1_MouseLeave(object sender, EventArgs e)
    {
      textBox1.BackColor = System.Drawing.Color.White;
    }

Noam B. Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...


Monday, September 20, 2010 4:59 AM

Thanks all,

I could focus the textbox now,... Actually I forgot to add a method Loaded method, which was the reason the textbox was not getting focus.

void LocalForm_Loaded(object sender, RoutedEventArgs e)
{
            System.Windows.Input.Keyboard.Focus(textbox1);
}

 

 

 

 


Thursday, October 7, 2010 8:39 AM

Hello,
         I have a another Problem,... I wanted to know what is the command to highlight or change the color of the default text when the textbox is focused ( i.e in case of Keyboard.Focus(textbox1) event is triggred).

Thanks,
Shilpa


Thursday, October 7, 2010 9:48 AM

Hi,

Try ForeColor, textBox1.ForeColor = System.Drawing.Color.Blue;

Thanks & Regards, Gokul.N


Monday, October 25, 2010 6:21 AM

Thanks Gokul,

                 But I couldnt use textBox1.ForeColor. Im developing an application in WPF, and I think that is the reason I cannot use "textBox1.ForeColor".

Thanks,

Shilpa


Monday, October 25, 2010 6:33 AM

Hi Shilpa,

For WPF, try like below

textBox1.Background = Brushes.Blue; 
textBox1.Foreground = Brushes.Yellow;

Thanks & Regards, Gokul.N