Question

How do i show superscripted string in Label or form name property.

enter image description here

I have found few questions like this one but was wondering if there is an way to do it for characters like 'a-z'?

Was it helpful?

Solution 2

You should better rely on the control meant for text-decoration: RichTextBox. You can configure it such that it looks like a Label. Sample code (richTextBox1 on main form):

richTextBox1.BackColor = richTextBox1.Parent.BackColor; //Backcolor of the RTB's container
richTextBox1.BorderStyle = BorderStyle.None;
richTextBox1.Text = "Bloggerx";
richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 10);
richTextBox1.SelectionStart = 7;
richTextBox1.SelectionLength = 1;
richTextBox1.SelectionCharOffset = 5;
richTextBox1.SelectionLength = 0;

Another option you have is relying on two different labels, adequately coordinated to get the appearance you want.

UPDATE

There is still another option (although I personally wouldn't use it) which is playing around with the encoding and the font families (some of them support super-and sub-scripts). Another answer has proposed what, in my opinion, is a very bad way to account for this alternative (relying on an external program); there are better ways to implement that. But, in any case, I don't think that this is a systematic, reliable and easy to implement method (you have to find the corresponding format and make sure that it accounts for all the situations you want); but something mention-worthy though.

OTHER TIPS

There are certain characters which are already there in charmap.exe and if you are specifically looking for X then it's possible using charmap utility.

1.Windows + R >> Open charmap.exe

2.Scroll down and look for your specific character, in your case it's 'X'

enter image description here

3.Select the charcter and paste into the property like label.Text

It will look something like

enter image description here

For this case there is really a simple answer. Use Unicode. just check https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts.

Here is an example

a=5ˣ;

The way to use it for a label is:

labelTemperature.Text = "84" + ("\u2070"); 

As for the use of RichTextBox, varocarbas I don't see a solution to the question but a way to convert the RichTextBox into its poor cousin the Label. And by the way the RichTextBox should be set to have no multi-line and be read only. But what makes a rich text box unusable is the fact that it doesn't support transparent colors which is the main strength of the Label. And as I faced this myself, the RichTextBox doesn't show on control.DrawToBitmap() created bitmap

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top