| Subscript/SuperScript Label .NET |
|
|
|
| Written by Talha Kalim |
| Wednesday, 11 February 2009 23:00 |
|
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:
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:
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.
2- In .Net Components select Browse and select the dll file (attached below).
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. |
| Last Updated on Wednesday, 11 November 2009 05:31 |
Copyright © 2009 FreshNova, by Talha Kalim and Waleed Al-Bahrawy







Comments
Well done Alex!
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!
Carlton, what did you have on your mind??
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...."
I haven't search long time, because fortunately you did it! Thanks so much!
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...