It seems the only options available to do multi-color on a string is either a bunch of label controls cleverly grouped together or to use a RichTextBox and play with the font properties as text is added to the control.
What I am looking for instead is some kind of control that can render some style of control codes out as color. Consider bash codes:
NORMAL='\e[0m'
GREEN='\e[0;32m'
BLUE='\e[0;34m'
echo -e "This text is ${GREEN}green${NORMAL} and this text is ${BLUE}blue${NORMAL}"
In the above, the words ‘green’ and ‘blue’ will be colorized with their respective colors. I was wondering if there was a control with some kind of feature like this, or will I have to code something myself?
Note, I only have the Express copy of VB 2010, and I would very much like to avoid third-party controls.
Are you specifically looking for something that understands ANSI control codes, or just something that accepts markup? If you just want something that accepts markup, you can use the
RichTextBox.Rtfproperty to set all the control codes and text with a single string.See http://msdn.microsoft.com/en-us/library/aa140277(v=office.10).aspx for the RTF specifications.
I would recommend programmatically generating a sample document, then reading the
Rtfproperty and using the resulting RTF code as a template for what you should generate. For reference, here’s a simple RTF document that has two color of text (plus the default) in Consolas (which fallback to Courier New):{\rtf1\deff0{\fonttbl{\f0\fmodern\fcharset0 Consolas {\*\falt Courier New};}} {\colortbl ;\red255\green0\blue0;\red0\green176\blue80;} \cf1 Hello\cf0 , \cf2 world\cf0 . }