How do i type a subscript in a label

Beginner

Well-known member
Joined
Mar 12, 2008
Messages
114
Programming Experience
Beginner
As seen from the picture:

transparentvf8.jpg


My approach was to create to labels and play with the location under properties (x,y) position values. But as you can see the closer the subscript the more it covers on the letter. Any help would be appreciated thanks.
 
I assume that putting the subscript label behind the other one doesn't work?

You could use an image of the text with subscript, or use a different control. Possibly an HTML label control if you have one, or something that can handle formatted text. You could possibly use a WebBrowser control, but that would be complete overkill and would probably mess up your background image (although how important is the background image?)

I'm no expert on WPF, but there might be a solution there too.
 
Solution Steps:

1- right click the solution name
2- menu 'Add'
3- option 'Class'
4- give the class the name: myLabel
5- copy paste this code

VB.NET:
Public Class myLabel
    Inherits Label
    Public NormalText As String
    Public SubScriptText As String
    Private SubScriptFont As Font = New Font(Font.FontFamily, Font.Size / 2, Font.Style)
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim Brsh As New SolidBrush(ForeColor)
        Dim NormalSize As Size = Size.Round(e.Graphics.MeasureString(NormalText, Font, New Size(Integer.MaxValue, Integer.MaxValue), StringFormat.GenericTypographic))
        e.Graphics.DrawString(NormalText, Font, Brsh, 0, 0, StringFormat.GenericTypographic)
        e.Graphics.DrawString(SubScriptText, SubScriptFont, Brsh, NormalSize.Width, NormalSize.Height \ 2, StringFormat.GenericTypographic)
        Brsh.Dispose()
    End Sub
    Private Sub myLabel_FontChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FontChanged
        SubScriptFont = New Font(Font.FontFamily, Font.Size / 2, Font.Style)
    End Sub
End Class

Now Build the project.
Build | WindowsApplicationX

2000913746179177964_rs.jpg


myLabel should appear at the top of your toolbox. Add a copy of it to your form and set the following properties in the properties window.


AutoSize = False
BackColor = Transparent
Font = Times New Roman, 16pt, Bold
ForeColor = Yellow
Size = 180, 30

2000298556496358677_rs.jpg


Add the following form load event handler:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyLabel1.NormalText = "Diametral Pitch P"
MyLabel1.SubScriptText = "d"
End Sub
 
As an HCI tip.. Your user interface uses 5 different fonts. When was the last time you saw Microsoft do that?
 
Thanx for the tip. So your saying 2 fonts are enuf ? One for the heading and the rest same font ?
 
Thanx for the tip. So your saying 2 fonts are enuf ? One for the heading and the rest same font ?

Pretty much, you rarely want/need to go beyond two fonts. Most of the time only one, but since you have a heading it should/could be in a different font.
 
Aha. I'll try that now. I created this GIF before seeing your last post.
Anyways tell me what you think:

12wh3.gif
 
Back
Top