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
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
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?
this is my actual result in my code
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.
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)
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
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();
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.