7

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'?

Community
  • 1
  • 1
Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
  • 1
    Have you seen [this](http://stackoverflow.com/questions/17704169/how-to-write-superscript-in-a-string-and-display-using-messagebox-show)?? – huMpty duMpty Oct 30 '13 at 12:40
  • That works only for the Numbers not for alphabets. – Sangram Nandkhile Oct 30 '13 at 12:47
  • There is a good solution here: [How to add superscript power operators in c# winforms](https://stackoverflow.com/questions/15042334/how-to-add-superscript-power-operators-in-c-sharp-winforms) – f4d0 Oct 31 '17 at 08:55

3 Answers3

7

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

Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
  • The option of choosing specific characters sets is a possible solution (not covered in my answer); but I don't think that you should recommend to rely on a different program and to do a manual copy/paste. I understand that the OP is looking for implementing this functionality in his program and you are suggesting to rely on a different program?! (why not suggesting creating the string in MS Word and copy it from there?) – varocarbas Oct 30 '13 at 13:49
  • @varocarbas: Charmap is not a 3rd party program. It's something developed by Windows to extend special character support and it comes with every Windows OS. Copy pasting from MS word or other utility will not help. – Sangram Nandkhile Oct 30 '13 at 14:27
  • Being an external program does nothing to do with its manufacturer (being Microsoft or any other company). The MS Word example was just to highlight that your proposal wasn't too adequate: if you choose the right font type, you can do this from Word too. As explained in the updated I wrote a while ago, if you want to propose this kind of alternatives you should rely on programming-based solutions (or even on an external application which might automated via code). Your solution is completely outside the expected requirements in this category (programming/C#/winforms). – varocarbas Oct 30 '13 at 14:53
  • @varocarbas: I think i have to agree with you as this solution doesn't seem to be working in Windows XP. It shows unidentified character. My bad.. so probably my answer will help the OP but will not be a good practice to follow. Thanks for pointing out. – Sangram Nandkhile Oct 30 '13 at 17:41
  • OK. Thanks for letting me know: this is what my help/SO is about: contributing towards delivering right answers. – varocarbas Oct 30 '13 at 17:45
  • For this case there is really a simple answer. Use Unicode. just check https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts. – Gogu CelMare Mar 16 '18 at 03:31
  • Here is an example `a=5ˣ;` 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. – Gogu CelMare Mar 16 '18 at 04:03
4

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.

varocarbas
  • 12,354
  • 4
  • 26
  • 37
  • How are you going to deal with the form name? – Sangram Nandkhile Oct 30 '13 at 17:44
  • @Sangram sorry but I am not following you. This code is a sample: for RichTextBox1 (assumed to be in the main form). Open a new project, put a richtextbox on it (RichTextBox1) and execute this code (from the Form Load event, for example) and you would see that it would work. If you prefer to put the RichTextBox inside a Panel, for example, you should convert this.BackColor into Panel1.BackColor (assuming that the panel is called Panel1). If you don't know the container (pretty unlike, IMO), you might get it from the richtextbox itself. – varocarbas Oct 30 '13 at 17:47
  • Sorry for confusing you and making you write detailed explanation. :P Yes i do understand every bit of it. The OP has asked question regarding label as well as Form name. I totally understand we could replace label by richtextbox but i was wondering if you could use something similar for form name. – Sangram Nandkhile Oct 30 '13 at 18:04
  • @Sangram I have updated my code: you can rely on the Parent property if you want. But, in any case, you have to be aware of the colors such that the font color is OK (not having black font on black background). And, additionaly, in these situations I prefer to write sample codes (= to explain the idea; not to deliver a working code for the OP just to paste it). – varocarbas Oct 30 '13 at 18:09
  • 1
    Just to add, don't forget to set the ReadOnly property of the RichTextBox control to true. – Sean Blaney Dec 14 '14 at 10:35
4

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

Gogu CelMare
  • 699
  • 6
  • 15