By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,537 Members | 926 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,537 IT Pros & Developers. It's quick & easy.

Changing font colors of concatenated strings

P: n/a
Let's say you're programming in VB.NET, and you have:

Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = "I am red"
str2 = "I am yellow"
str3 = "I am dark green"

With TextBox1
.Text = str1 & ", " & str2 & ", " & str3
.SelectAll
.Copy
End With
....and you want to copy 'str' to the clipboard, with "I am red" in red
font, "I am yellow" in yellow font, and "I am dark green" in dark green
font?
I feel like I'm missing something obvious...
Thanks!

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"JoelW" <js******@rockwellcollins.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Let's say you're programming in VB.NET, and you have:

Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = "I am red"
str2 = "I am yellow"
str3 = "I am dark green"

With TextBox1
.Text = str1 & ", " & str2 & ", " & str3
.SelectAll
.Copy
End With
...and you want to copy 'str' to the clipboard, with "I am red" in red
font, "I am yellow" in yellow font, and "I am dark green" in dark green
font?
I feel like I'm missing something obvious...
Thanks!


You are copying text to the clipboard. The clipboard does not contain
anything for colors. It has no UI to display colors/strings. All it cares
about is that you are copying "data" to the clipboard to be used at a later
time. What you are copying from may display the strings in colors. For
example, if you are copying from a Rich Text Box, then when you copy the
text, you are copying the format (the Rich Text format) as well as the text.
The "data" is the format code which contains the text you are copying.

Hope this helps :)

Mythran

Nov 21 '05 #2

P: n/a
Then how do I get the different sections of the concatenated string to
show up as different colors in this instance?

Nov 21 '05 #3

P: n/a
JoelW wrote:
Then how do I get the different sections of the concatenated string to
show up as different colors in this instance?


It all depends on what you are coping to. If you sent data in html
format and the object you are pasting to accepts that format then it
will work. if you paste in Rich text format then the object you are
pasting to needs to accept that as well.

Chris
Nov 21 '05 #4

P: n/a
Hi,

The textbox does not support color. Use a richtextbox instead.
This code will place the text in the color you want in the richtextbox and
then copy it to the clipboard.

RichTextBox1.SelectionColor = Color.Red
RichTextBox1.SelectedText = "I am red" & ControlChars.NewLine
RichTextBox1.SelectionColor = Color.Yellow
RichTextBox1.SelectedText = "I am yellow" & ControlChars.NewLine
RichTextBox1.SelectionColor = Color.DarkGreen
RichTextBox1.SelectedText = "I am dark green" & ControlChars.NewLine
RichTextBox1.SelectAll()
RichTextBox1.Copy()
Ken
---------------------
"JoelW" <js******@rockwellcollins.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Let's say you're programming in VB.NET, and you have:

Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = "I am red"
str2 = "I am yellow"
str3 = "I am dark green"

With TextBox1
.Text = str1 & ", " & str2 & ", " & str3
.SelectAll
.Copy
End With
....and you want to copy 'str' to the clipboard, with "I am red" in red
font, "I am yellow" in yellow font, and "I am dark green" in dark green
font?
I feel like I'm missing something obvious...
Thanks!
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.