# [.net] HTML in labels

This topic is 4791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, guys. I can't figure out for the life of me how to use html in labels. Specifically, I want to use subscript in my label, but the <html> and text just gets displayed. Thanks in advance.

##### Share on other sites
If you're referring to the System.Windows.Forms.Label, then I'm afraid you can't. If you just want decorated text, try using RTF or a LinkLabel.

##### Share on other sites
What I'm looking to do is use subscripted text. And RTF doesn't seem to be working, either. Maybe I'm just typing in the html wrong. I tried:

<html>uk<html>

Sorry, the forum automatically converts the instructions to how they r supposed to display k. So I'm guessing that part is right.

##### Share on other sites
Quote:
 Original post by yaroslavdWhat I'm looking to do is use subscripted text. And RTF doesn't seem to be working, either. Maybe I'm just typing in the html wrong. I tried:ukSorry, the forum automatically converts the instructions to how they r supposed to display k. So I'm guessing that part is right.

An RTF reader won't parse or render HTML, so that's probably why you're not seeing results. RTF does have a "\sub" reserved word for subscripts, though. Here's a short RTF document that shows uk in Arial 10pt, produced with WordPad (my RTF's a little rusty):

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 u\sub k\nosupersub\fs24\par}

HTH,

##### Share on other sites
Well, I copy-pasted your text into the Text property of RTF box and it still doesn't work. :(

##### Share on other sites
Quote:
 Original post by yaroslavdWell, I copy-pasted your text into the Text property of RTF box and it still doesn't work. :(

The Text property is the non-literal (non-RTF) text. What you want is the Rtf property. To put it another way, ".Text is what you see, but .Rtf is what you get".

##### Share on other sites
Thanks a bunch. Is there anything that will display subscript values in editor, however? That'd really help.

##### Share on other sites
Also, the compiler complains of illegal escape characters such as \sub in the string.

##### Share on other sites
Use the @ form of the string;

String s = @"some\substring";

of escape the backslashes:

String s = "some\\substring";

##### Share on other sites
Ah, of course. You have to forgive me, I haven't programmed in months. However, if anyone can help me out, I'd still love a control that would display what I want in the designer.

##### Share on other sites
AFAIK, there's nothing in the standard Label/TextBox subset that'll do that. You can fake superscripts with the font glyphs for 2 and 3, but that's about it. One suggestion, though -- you mentioned HTML. If you're actually writing a webpage, RTF is not the way to do it. You'll want one of the Renderer controls for HTML or something of that kind (at least in .NET 2.0), but I haven't used those before. I'm sure a Google search could tell you more.

##### Share on other sites
Alright, thanks. What I think I'm gonna end up doing is setting the text to uk, so that's what's gonna display in the editor. And then I'm gonna set the subscript in the Rtf field. Thanks for everyone's help.