Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I need to create a Label where I can color any character in the Text with a different color. The property I want to use is:

Label.Text(PositionOfCharacter as Integer).color = color.ColorName

I am using VB.Net.

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 5-Oct-14 2:51am    
This is quite solvable, but you need to tell us what do you mean by Label. More exactly, what is the UI library you want to use and/or application type (System.Windows.Forms, WPF, anything else?)
—SA
Member 11127394 5-Oct-14 7:22am    
I am using VB.NET.

Label is the Label control in System.Windows.Forms.

Can you please suggest a solution in VB.NET?

Thanks
Sergey Alexandrovich Kryukov 5-Oct-14 12:51pm    
I already answered. First link in Solution 1 is the very convenient solution. You create you label class based on the HTML Renderer based on RichTextBox and use HTML markup to show parts of the label in different color or other markup.
—SA

1 solution

Please see my comment to the question. You need to specify what do you want to use.

The solution can be found in these CodeProject articles:
For System.Windows.Forms: A Professional HTML Renderer You Will Use[^];
For WPF: WPF HTML Supported TextBlock[^].

If you use ASP.NET, the solution seems to be trivial, so it would not need further discussion. If you use anything else, try to use the very idea.

Wou will also need to solve the problem of the keyboard hot keys (accelerators) working by underscored label character (using '&' or '_' prefix for Forms and WPF) which you can solve handling the keyboard events on the parent form/window.

—SA
 
Share this answer
 
Comments
Maciej Los 5-Oct-14 16:22pm    
+5!
Sergey Alexandrovich Kryukov 5-Oct-14 16:31pm    
Thank you, Maciej.
—SA

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