changing the font color dynamically?

ARC

Well-known member
Joined
Sep 9, 2006
Messages
63
Location
Minnesota
Programming Experience
Beginner
Hey, so I made a fake chat interface, kind of based on a text based adventure. So there are a bunch of case statements for commands you can make in game.

I have timers that are set at different intervals, and they display text in the text box on the main form:

VB.NET:
Private Sub Timer13_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer13.Tick
Me.TextBox1.Text = ""
Me.TextBox2.Text = Me.TextBox2.Text + "Are we there yet?" & ControlChars.NewLine & ControlChars.NewLine
Me.TextBox2.Focus()
Me.TextBox2.ScrollToCaret()
Me.TextBox1.Focus()
End Sub

Is there a way I can have this font color to be something other than white -- and hopefully put that in the timer event?
 
Use RichTextBox control, Select where to start new text, set SelectionColor, add the text.
VB.NET:
rt.Select()
rt.Select(rt.TextLength, 0)
rt.SelectionColor = Color.Blue
rt.AppendText(text)
 
Thanks :) I assume this can work on a specific chunk of text anywhere in the richtextbox yeah?

If so, would I be sending the string in textbox1.text to a variable first, then using the apendtext you suggested to alter it's color, then send the blue text like

'richtextbox2.text = richtextbox2.text & bluetext

Or would I just use the timer event code to write the text itself as blue and dont bother with adding it to it's own string variable first?

example being I want commands that the user types in to be in Blue, but other text that appears in the textbox as Green.
 
SelectionColor applies to any selection you make of text in Richtextbox. If you write new text or insert anywhere it will take the same color as at current index. If you are appending text and want it to be some specific color use the code I posted, it's easier than to append text and calculate its size and make the full selection and then color it.

Colorizing special keywords is one of the biggest topics of rich text. There are at least 50 different ways of handling that stuff. I have no special recommandation on how you should do this. Do a lot of research on the web and/or figure out a method that works for you.
 
Back
Top