37

If I want to upload a text file into the textbox and want to highlight certain words with a font color change, how can I do that without drawing the text?

Thank you.

7
  • 1
    Is that a textbox or richtextbox? Commented May 11, 2010 at 18:49
  • 2
    Using what technology? WinForms? WPF? Commented May 11, 2010 at 18:50
  • This question can't be answered without at least telling us whether you're asking about a desktop or a web application. (I suspect it's the latter.) Commented May 11, 2010 at 20:19
  • I am running this on Visual Studio, C# Windows Application. And I am working with the regular textbox from the tool menu. Commented May 11, 2010 at 20:21
  • You cannot do it with a regular textbox control. RTB required. Commented May 11, 2010 at 20:58

2 Answers 2

41

Assuming WinForms, the ForeColor property allows to change all the text in the TextBox (not just what you're about to add):

TextBox.ForeColor = Color.Red;

To only change the color of certain words, look at RichTextBox.

Sign up to request clarification or add additional context in comments.

7 Comments

this does not "highlight certain words" but changes the colour of all words. I don't think this is a correct answer
The OP has clearly specified that he wants to highlight through a font colour change... So all he needs to do is change the colour.
But he specified "highlight certain words" and if you change the ForeColor of the Text, all the text will change, not the "certain words".
@AnderBiguri: I believe the RichTextBox can do it, though I have never used it myself. You're maybe right about the "certain words", though.
it depends on if by highlighting he meant changing text colour or highlighting like with a highlighter
|
4

RichTextBox will allow you to use html to specify the color. Another alternative is using a listbox and using the DrawItem event to draw how you would like. AFAIK, textbox itself can't be used in the way you're hoping.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.