Label Control - Color Specific words in the TEXT value

1 Answer 20 Views
Label
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Mark asked on 15 May 2024, 02:17 PM

How can a specific color be set to specific words in the TEXT value of a LABEL?

I have tried using the following

radLabel.Text = "<HTML><color=red>Hello<color=black>World</HTML>";

But it doesn't work, I get the following when running our code.

<HTML><color=red>Hello<color=black>World</HTML>

Any help would be greatly appreciated.

 

Thank You

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 16 May 2024, 01:32 PM

Hello, Mark,

I tested the provided code snippet that sets the Text property, and RadLabel shows the text correctly. This is the result on my end:

Can you please make sure the radLabel.UseCompatibleTextRendering property is set to true. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 29 May 2024, 11:34 AM

Yeah, that is set to TRUE, but it's still not working as I would expect.

 

Note: the RadLabel is contained inside a TableLayoutPanel, could this be causing the issue?

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 29 May 2024, 11:37 AM

this is my actual result in my code

Nadya | Tech Support Engineer
Telerik team
commented on 31 May 2024, 01:41 PM

Hello, Mark,

It is strange that the html formatting for the text is not respected on your end. I have added the RadLabel into TableLayoutPanel as you specified and it is still working correct on my side. I attached my test project for your reference so that you can open it and compare it with yours.

I have noticed in the provided picture there are brackets () that wraps the text which are basically not needed. I am not sure if they re the problem but you can try to remove them and use semi columns: "<HTML><color=red>Hello<color=black>World</HTML>".

I hope this helps. Let me know if I can assist you further. 

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 31 May 2024, 02:51 PM

They are needed, as I am looking to do this as a Results

 

I am looking for these results, but it's not happening. Could it be the brackets "(" ")" I am using? It's possible.

Total Recorts: 99,990 (74,601)

 

Nadya | Tech Support Engineer
Telerik team
commented on 03 Jun 2024, 03:27 PM

Hello, Mark,

I am not sure what is happening on your end. In the project that I provided to you I am able to set the text with red numbers as you requested:

radLabel1.Text = "<HTML><color=black>Total Records: 99,990<color=red>(74,601)</HTML>";

Did you open the provided project on your end? Does the RadLabel show correct in it?

Regards

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 03 Jun 2024, 05:23 PM | edited

We don't want the "(" or ")" to be red.   Here is our script

 

StringBuilder sb = new StringBuilder(); sb.Append($@"<HTMLTotal Records: {ntsRadGridViewData.RowCount:N0}"); if (errors > 0) { sb.Append(@$" (<color=red>{errors:N0}<color=black>)"); } sb.Append(@$"</HTML");

radLabelStatus.Text = sb.ToString();


Nadya | Tech Support Engineer
Telerik team
commented on 06 Jun 2024, 07:46 AM

Hello, Mark,

Please refer to the following code snippet which achieves the desired result using StringBuilder and Append(text):

 StringBuilder sb = new StringBuilder();

 sb.Append($@"<HTML>Total Records: {radGridView1.RowCount:N0}");
 int errors = 3;

 if (errors > 0)
 {
     sb.Append(@$" (<color=red>{errors:N0}<color=black>)");
 }
 sb.Append($@"</HTML>");

 radLabel1.Text = sb.ToString();

I hope this helps. If you have other questions, please let me know.

Tags
Label
Asked by
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or