Rotating Text in a Label Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to rotate it 180 degree so it is upside down. What is the easiest way to accomplish this?

Thank you
John
 
Hi,

Private Sub Label1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
Label1.Text = ""
e.Graphics.TranslateTransform(Label1.ClientSize.Width,
Label1.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString("upside down string", Label1.Font,
Brushes.Black, RectangleF.op_Implicit(Label1.ClientRectangle))
End Sub

Ken
 
Ken
Worked AWESOME, as you know. I am also trying to "middle.center" the text in the box. I've tried about ten different ways. What code do I need to add and where does it need to go

Thanks for your help
John
 
Hi,

Use a string format

Private Sub Label1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
Label1.Text = ""
e.Graphics.TranslateTransform(Label1.ClientSize.Width,
Label1.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString("upside down string", Label1.Font,
Brushes.Black, RectangleF.op_Implicit(Label1.ClientRectangle), sf)
End Sub


Ken
 
Ken...One more question about this. I am now trying to rotate text either 90 degrees or 270 degrees. I'm not sure of direction yet. Here is my code based on your earlier example:

Private Sub Label14_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label14.Paint
Dim sf As New StringFormat
sf.Alignment = (StringAlignment.Center)
sf.LineAlignment = (StringAlignment.Center)
Label14.Text = ""
e.Graphics.TranslateTransform(Label14.ClientSize.Width, Label14.ClientSize.Height)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(Label4.Text, Label14.Font, Brushes.Black, RectangleF.op_Implicit(Label14.ClientRectangle), sf)
End Sub

When I display the form....the text is not visible at all. Any idead?

Thanks,
John
 
Well...here's some more information. If I use an angle of 180 it's right in the center of the label box. If i slowly increment it by 10 degrees at a time it seems to swing on a radius that is centered in the lower right hand corner of the label box. Either the first or last "eGraphics" line need to take into account the size of the label box and probably somehow divide something in half. I've tried for about two hours now but not understanding the parameters on those two lines completely makes it quite difficult to decipher

Ideas
John
 
Back
Top