FreshNova - Home

Wednesday 10th of March 2010

Home C# Tutorials Subscript/SuperScript Label .NET
Subscript/SuperScript Label .NET PDF Print E-mail
Written by Talha Kalim   
Wednesday, 11 February 2009 23:00

 

superscript Have you ever needed to use a label with subscript or superscript text and searched all over the net and not found anything? I know I have and after searching for a long time and not finding anything, I decided to make my own label using C#. The custom superscript, subscript C# label turned put to work just fine for me and helped me overcome my problem, so I would like to share it with everybody. By the way this label is for the Windows Forms Applications only.

 

I call it the FNLabel, and it is just a simple label that extends the .NET label. The FNLabel should work with any .Net language. I simply overrid the OnPaint method and used graphics.DrawString and drew the string while offsetting the superscript and subscript text in the label. I used two characters for marking the start and end of superscript and subscript text. Just add it to your toolbox and start using it. You can download it from the attachments below (Read More..)

 

Here is how you should use the label:

 

properties

1- In the properties window of the label you will notice that there are 4 new properties of the label.

 

2- SubscriptFont: This is the font to be used in the subscript text. I added it to give me some flexibility. The default size is some done by taking a ratio of the font of the normal text.

 

3- SuperscriptFont: This is the font to be used in the superscript text, similar to the subscript font, again for flexibility.

 

AND NOW THE MORE IMPORTANT STUFF

4- Superscipt/Subscript Marker: These marekers indicate the beginning and end of the superscript and subscript text. You can set them to anything. I added these so just in case you need to use the default values in your actual text you can change the marker.

The defaults for the superscript and subscript are ^ and ` respectively. Here is the result of the above text:

 

view

 

You might need to resize the label for the text to fit in. I cooked this up pretty fast so, although it worked just fine for me, there might be some problems, so I would like to hear feedback, and I would be glad to fix any reported issues.

 

To add it to the toolbox and use it, follow the steps below :

 

1- First Right-Click the toolbox and select Choose-Items.

 

choose_items

 

2- In .Net Components select Browse and select the dll file (attached below).

 

select_dll

 

3- You should find the FNLabel in your toolbox now, drag and drop it onto your form and off you go, fix the properties as needed and off you go...


Please feel free to leave your comments, If you have any problems just let me know and I will try my best to help you out.

Attachments:
FileFile sizeLast Modified
Download this file (FNLabel.dll)FNLabel.dll7 Kb12/02/09 18:17

Comments

avatar Alex G.
0
 
 
Thank you very much! Worked great for my purposes.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar bthuan
0
 
 
Thks for your good sharing.
Well done Alex!
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
It is good to see that the label worked out fine for you guys, If you have any feedback be sure to let me know.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Nigel
0
 
 
Awesome work. I tried using it to display a single character and it wouldn't show it...

For example:

label.Text = "h" //Shows nothing
label.Text = "h " //Shows 'h'
label.Text = "hi" //Show 'hi'

It would be great to see that fixed!
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Carlton
0
 
 
This works really really well, although now there are several other control types I'd like to fit this into. Is it possible that code for this control will be made available, so as to be adapted to other controls?
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
Nigel, Sorry for my late reply but I have been a little busy with my studies. I will look into it now and let u know probably sum problem with loops and indexes.

Carlton, what did you have on your mind??
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
Alright guys seems this control is being used a little more than I expected. I enabled emails so any body who wishes to recieve replies can leave his email here.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Carlton
0
 
 
The control I'm having issue with is the ListView (I'm actually using an open-source enhanced version of the list view, ObjectListView). I would like to put superscript in some of the column headers.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
OK I will look into it Carlton but I am undecided as to publish the source code. I will keep you updated. By the way there is a problem in it as pointed out by Nigel.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Earthed
0
 
 
Dear Talha, Great work. But I have one issue with the following text: Subscript `cls`

In investigating how MS-word downsizes either the default super or subscript font, it is normally half the point size as the original text.

When using Arial font such that:
- normal font arial 12pt and
- subscript font arial 6pt

The supercript seems ok.

The subscript text does not lower to an appropriate offset position
It only works ok when the size of the subscript and normal fonts are the same.
In my case above, the subscript text does not offset far enough
Would love to "How to...."

Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar negleden
0
 
 
You are my hero! I make my first seriously project and I met this problem yet!
I haven't search long time, because fortunately you did it! Thanks so much!
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
Hey Earthed,

Thanx for pointing that out. I am running very busy these days with exams and course projects. I intend to sort out the problems you and other people have pointed out as soon as I find some time. (probably by the end of this month).

Thanx
Talha Kalim

negleden

Its great to know that the label was of help to you. Hopefully I will be able to make improvements to it so that I can take care of the problems mentioned above...
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar chris
0
 
 
seems font color cannot be changed. Use black as backcolor. Font color cannot be changed to white.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Peter
0
 
 
I have the same problem with the font color. It can't be changed to another one, but I really really need white as font color. Would be awesome if this could be fixed some time. Other than this awesome label applications. Thanks a lot.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Talha Kalim
0
 
 
Guys, I will try to fix the font problem and get back to you just need a little time thanx...
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar dan
0
 
 
nice review
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Last Updated on Wednesday, 11 November 2009 05:31
 

Archive

 

Categories


Copyright © 2009 FreshNova, by Talha Kalim and Waleed Al-Bahrawy