Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to change the color of a string, but only a portion of the string. This string will be pull and send out via email (smtp).

If GroupBox1.Enabled = True Then
Q1 = ("Question 1 - Symptoms: " + GroupBox1.Enabled.ToString) '<--I want to change the color of the string pulled from the groupbox to 'RED'
Else
Q1 = ("Question 1 - Symptoms: " + GroupBox1.Enabled.ToString) '<--I want to keep this color the default white. I assume this as is will do that trick as is.
End If


Any suggestions? if this is not possible, what other methods can be done and still call on the strings provided by the form? I have about 12 other string calls.

What I have tried:

<pre>If GroupBox1.Enabled = True Then
Q1 = ("Question 1 - Symptoms: " + GroupBox1.Enabled.ToString) '<--I want to change the color of the string pulled from the groupbox to 'RED'
Else
Q1 = ("Question 1 - Symptoms: " + GroupBox1.Enabled.ToString) '<--I want to keep this color the default white. I assume this as is will do that trick as is.
End If
Posted
Updated 6-Oct-20 18:52pm
Comments
Dave Kreskowiak 6-Oct-20 23:55pm    
This makes no sense. Strings do not have a color. it is only when they are displayed by a control that you might get a property in the control to give the displayed content a color.

GroupBox contains other content controls, like ListBox, Labels, TextBoxes, ... but not "strings".

Also, there's no standard control in HTML that is a "group box". You're going to have to describe your control layout and what they are displaying better than you have.

1 solution

If I understand correct, you seek to highlight some text while sending an email.

For highlighting text via some color, you would need to use HTML or RTF format of text. This would enable you to have text formatting that can be sent in an email.

Look at similar query answered before: How to send Color content as a email using smtp in C#?[^]

Simplest though would be marking the mail message body as HTML and assigning the needed text to it in html format as per need.
Like:
msg = new MailMessage("xxxx@codeproject.com",
                "yyyy@codeproject.com", "Message from CodeProject",
                "This email sent by the CodeProject<br />" +
                "this is bold text!");

msg.IsBodyHtml = true;


Now, for any reason you were looking for having multiple colors for a text of ONE label. That would not be possible. A label has single color.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900