Rotating Text in .NET
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Rotating Text in .NET

  1. #1
    Join Date
    Feb 2003
    Posts
    33

    Rotating Text in .NET

    Is there an easy way to rotate text in VB .NET? I've searched the other forums and found some solutions, but everytime I use a solution that involves API calls, etc. I almost always end up finding an easier way to do it in VB .NET. I'm hoping to avoid implementing more than I have to. I just want to print rotated text in a picturebox. Thanks!

    Jerry

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878
    Code:
    ' This example shows how to draw rotated text on a label control.
    Private Sub Label_Paint( _
        ByVal sender As Object, _
        ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
    
        ' Create a new font object to be used by the DrawString method
        Dim NewFont As New Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Point)
    
        ' Get a handle to the graphics object of the label
        Dim g As Graphics = e.Graphics
    
        ' Do the transformation
        g.TranslateTransform(0, 150)
        g.RotateTransform(-90)
    
        ' Draw the text
        g.DrawString("Rotated text", NewFont, Brushes.Blue, 0, 0)
    
        ' Reset the transform so subsequent drawing wont be affected
        g.ResetTransform()
    
    End Sub
    Iouri Boutchkine
    iouri@hotsheet.NOSPAM.com

  3. #3
    Join Date
    Feb 2003
    Posts
    33
    Thanks! I'll play with that and see if it does what I need. I knew there had to be an easy way to do this. I'm really starting to like VB .NET.

    Jerry

  4. #4
    Join Date
    Feb 2003
    Posts
    33
    Alright... Played with that and got it do just what I wanted as far as rotating the text. The next trick:

    Make the text a little transparent.

    Any thoughts on how to adjust the opacity of the text that is drawn so you can see the image through the text? Thanks!

    Jerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center