Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy one

Status
Not open for further replies.

BrasilianGuy

IS-IT--Management
Oct 27, 2005
25
US
How do I code a textbox to highlight the text or the background clicking on it?

Lets say that I have box 1 2 and 3.... I wanna be able to highlight one of them or all of them as I wish!

Thanks in advance

Marcus

Ps.: I'm newbie on C#.
 
try setting the Forecolor or Backcolor in the textbox object, something like textbox.ForeColor = Color.Yellow;
 
Something like a

onclick()
textbox.ForeColor = Color.Yellow

??

Thanks
 
textbox.BackColor = Color.FromKnownColor(KnownColor.Highlite);

Will give you the default system highlite color.

If you just want to select the text in a textbox, then textbox.SelectAll();
 
TextBox.BackColor = SystemColors.Highlight

saves a few keystrokes ;)

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Thanks

How do I actvate this command by clicking in the textbox??

Thanks again

Marcus
 
in the designer select the textbox, click the lightning bolt in the properties window, and double click the event you want to handle. You could do it for mouse overs. TextChanged is the standard textbox event
 
I tried this

private void TextBox1_backcolorchanged(object sender, MouseEventArgs e)
{
this.TextBox1 = SystemColors.Highlight;
}

still didn't work

Thanks

Marcus
 
If you want to highlite the box when it's clicked, then activate the Click event. Click on your TextBox in the designer (on the form) and click the Lightning Bolt icon above the properties window. Then double click next to the words "Click" in the properties window.

private void TextBox1_Click(object sender, EventArgs e)
{
this.TextBox1.BackColor = SystemColors.Highlite;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top