[RESOLVED] [2005] Display Vertical Text in a label ?
I've searched for vertical text, but was unable to find an answer on how to display vertical text in a label; eventhough there is an indication that it can be done.
I tried to use the following sub but all I can get to display a emptyness.
VB Code:
Public Sub DrawYAxis()
Dim bm As Bitmap = New Bitmap(30, 50)
Dim g As Graphics = Graphics.FromImage(bm) 'Graphics object created from bitmap
Dim drawFont As New Font("Arial", 8)
Dim BlackBrush As New SolidBrush(Color.Black)
Dim What As String = "Y Axis"
g.DrawString(What, drawFont, BlackBrush, bm.Height, bm.Width)
g.TranslateTransform(CSng(bm.Width / 2), CSng(bm.Height / 2))
g.RotateTransform(90)
YAxisLabel.Image = bm
g.Dispose()
End Sub
any guide to the blind will be appreciated! Thanks.
Re: [2005] Display Vertical Text in a label ?
You could sort the label into an array then display 1 letter with an
in between.
Re: [2005] Display Vertical Text in a label ?
Thanks. However, what I want to do is have the Y Axis displayed vertically along the Y axis of a graph. This will also be used to display other text non-horizontally. I've been searching the web, but so far no one has come close the actually showing how to do what i need (at lease I can't figure it out. What is throwing me off is trying to create a graphics object from a label. It does not have to be a label; a picturebox of panel will also work.
Re: [2005] Display Vertical Text in a label ?
VB Code:
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "H" & Environment.NewLine & "i" & Environment.NewLine & Environment.NewLine _
& "T" & Environment.NewLine & "h" & Environment.NewLine & "e" & Environment.NewLine & _
"r" & Environment.NewLine & "e"
End Sub
Will display "Hi There" downward.
Re: [2005] Display Vertical Text in a label ?
Thanks, francisstokes, for your help. I don't want the text to read vertically one letter at a time, but the actually be sideways, as if the page was turned. I do not have a image to show you. I want the X Axis to be view horizontally along the top of the grid, and the Y Axis to be view turned 90 degrees along the left edge of the grid.
jmcilhinney, in another thread indicated that this was posible.
Re: [2005] Display Vertical Text in a label ?
Sorry i understand what you mean now. Does it have to be a label?
Re: [2005] Display Vertical Text in a label ?
Working with RotateTransform is a pain in the neck. YOu have to set the rotate before you do the drawing, and then it wacks up the X and Y coordinates, since you have to imagine them all rotated.
I made a picturebox instead of a label, and this worked..
VB Code:
Public Sub DrawYAxis()
Dim bm As Bitmap = New Bitmap(300, 500)
Dim g As Graphics = Graphics.FromImage(bm) 'Graphics object created from bitmap
Dim drawFont As New Font("Arial", 12)
Dim BlackBrush As New SolidBrush(Color.Black)
Dim What As String = "Y Axis"
g.RotateTransform(90)
'g.TranslateTransform(CSng(bm.Width / 2), CSng(bm.Height / 2)) 'I couldn't get this to work upside down because I didn't feel like playing with the math all day :)
g.DrawString(What, drawFont, BlackBrush, 0, -20)
PictureBox1.Image = bm
g.Dispose()
End Sub
Re: [2005] Display Vertical Text in a label ?
No, it does not need to be a label. I came across this sub, I found in "Bobo Color Picker" from PSC, that I incorporated into the program. It is close to what I want, except that I can't control the faceing of the text.
VB Code:
Public Sub DrawYAxis(ByVal TargetBox As PictureBox, ByVal lblText As String)
'Printing text vertically
Dim drawFont As New Font("Arial", 10)
Dim TextBrush As New SolidBrush(System.Drawing.SystemColors.MenuText)
TargetBox.Image = New Bitmap(TargetBox.Width, TargetBox.Height)
Dim g As Graphics = Graphics.FromImage(TargetBox.Image)
Dim sFormat As New StringFormat
sFormat.FormatFlags = StringFormatFlags.DirectionVertical
g.DrawString(lblText, drawFont, TextBrush, 0, 0, sFormat)
TargetBox.Invalidate()
TextBrush.Dispose()
g.Dispose()
sFormat.Dispose()
End Sub
I know that there must be a better way to control the direction of text.
1 Attachment(s)
Re: [2005] Display Vertical Text in a label ?
The ElementsEx library in my signature has a RotatedLabel control that allows you to place text at any angle as simply as adding a regular Label.
Re: [2005] Display Vertical Text in a label ?
:) Thanks, jmcilhinney. I will check it out.
This revised code does what I want:
VB Code:
Public Sub DrawYAxis(ByVal TargetBox As PictureBox, ByVal lblText As String)
'Printing text vertically
Dim drawFont As New Font("Arial", 10)
Dim TextBrush As New SolidBrush(System.Drawing.SystemColors.MenuText)
TargetBox.Image = New Bitmap(TargetBox.Width, TargetBox.Height)
Dim g As Graphics = Graphics.FromImage(TargetBox.Image)
g.TranslateTransform(0, TargetBox.Height) ' (0, textwidth)
'set the rotation angle for vertical text
g.RotateTransform(270)
g.DrawString(lblText, drawFont, TextBrush, 0, 0)
TargetBox.Invalidate()
TextBrush.Dispose()
g.Dispose()
End Sub
Thanks all the the help.