Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphics.Drawstring - toggle vertical orientation 1

Status
Not open for further replies.

JSLUIS

Programmer
Aug 18, 2003
11
NL
Hello:
I'm use the Graphics.Drawstring method with the drawFormat.FormatFlags = StringFormatFlags.DirectionVertical.
This results in a vertical textstring which starts up and goes down.
I need to toggle this orientation so that the text starts down and goes up.


Does anyone know if there's a way to do this?

Thank you for your help,
Jaap Sluis
 
I usually draw my graphics onto an in-memory bitmap, and draw that bitmap onto the form at one time to avoid multiple drawing operations on the form's graphics objects.

That being said, you can call a RotateFlip on the bitmap to change the orientation. There may be another way that's built in, but here is an example with the bitmap. Note that in this example, I am creating the bitmap in the paint event. Normally, it would only be created when the form loads or it's dimensions need to be changed after a form resize.

Code:
    Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = e.Graphics

        Dim bmp As New Bitmap(Me.Width, Me.Height)
        Dim g2 As Graphics = Graphics.FromImage(bmp)
        g2.Clear(Me.BackColor)

        Dim sf As New Drawing.StringFormat
        sf.Alignment = StringAlignment.Center
        sf.FormatFlags = StringFormatFlags.DirectionVertical
        g2.DrawString("Hello World", Me.Font, Brushes.Red, New RectangleF(50, 0, 400, 400), sf)

        bmp.RotateFlip(RotateFlipType.Rotate180FlipNone)

        g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height)
    End Sub
 
I think your solution will do if you are only writing text.

But I am making a drawing in wich I use textstrings(horizontal and vertical);
So if I RotateFlip my bitmap the whole drawing is rotated.
 
Have this piece of code that lets you rotate a drawstring.
You can use this in combination with RiverGuy code without the rotateflip

Code:
[COLOR=green]'Location of the rotation[/color green]
g2.TranslateTransform(x, y)
[COLOR=green]'How much tekst needs to be rotated[/color green]
g2.RotateTransform(45)
[COLOR=green]'Color of the text[/color green]
b = New SolidBrush(Color.Navy)
[COLOR=green]'Lettertype [/color green]
Dim varFontBalk As Font = New Font("Arial", 10)
Dim Locatie As New RectangleF(0, 0, 100, 100)
g2.DrawString("Hello", varFontBalk, b, Locatie)
[COLOR=green]'Reset transformation [/color green]
.ResetTransform()

It has been a while for me in drawing so I can't comment on all. So you have to excuss me on that.
But wanted to give you the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top