You want to want to write a text string on a label vertically, bottom to top (rotated 90 degrees anticlockwise
Draw the String using the DrawString method of the Graphics Class. Use Transformations to move the start point of the text downwards and to rotate the text from horizontal to vertical.
Reading some of the textbooks and articles that deal with Graphics Transformations can seriously damage your sanity! Luckily, the transformations we are going to apply to this label’s text are relatively easy to follow if, as before, we break the code down into manageable, understandable chunks.
Here is the code which produces the label text shown in the graphic at the top of this page:
Private Sub Label2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label2.Paint
' Draw text vertically, from bottom to top
' The text to be drawn on the label
Dim strText As String = "Bottom to Top"
' The Graphics object for this label
Dim g2 As Graphics = e.Graphics
' The font, size and style to draw text
Dim fnt As Font = New Font("Arial", 12, FontStyle.Bold)
' Move origin point of text down to bottom of label
g2.TranslateTransform(13, Label2.Height - 25)
' Rotate the text the required number of degrees
' Optional TextRenderingHint
g2.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
' Finally we draw the string
g2.DrawString(strText, fnt, Brushes.White, 0, 0)
That's it! Run this code and the text will appear in the label bottom to top. There is a more detailed breakdown on the next page.