Solved

Rotating text around it's axis with GDI+

Posted on 2004-08-26
1
506 Views
Last Modified: 2009-07-29
I'd like to know how to rotate a string around it's center/middle axis.  (Presumably using Graphic.RotateTransform) I have looked at the TranslateTransform method, but I cannot figure out how to use it properly.

 I would be extremely thankful for any assistance in this endavour.

0
Comment
Question by:mjohansson
1 Comment
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 11911772
Try this
 Dim angle As Integer
 Dim f As Font = New Font("Arial", 10)
Dim s As String = "Test String"

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        angle = CType(TextBox1.Text, Integer)'enter the angle to TextBox1
        Me.Refresh()' to repaint the form

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim sz As Size = Me.Size
       'find the middle of the form
        Dim Middle As Point = New Point(sz.Width / 2, sz.Height / 2)
        e.Graphics.TranslateTransform(Middle.X, Middle.Y)

        'rotate
        e.Graphics.RotateTransform(angle)
        ' Create a new StringFormat object to
        Dim format As StringFormat = New StringFormat(StringFormatFlags.NoClip)
        format.Alignment = StringAlignment.Center
        format.LineAlignment = StringAlignment.Center
        e.Graphics.DrawString("A simple TextString ", f, Brushes.Black, 0, 0, format)

    End Sub

=======another========
 Private Sub Form1_Paint( _
        ByVal sender As Object, _
        ByVal e As System.Windows.Forms.PaintEventArgs _
    ) Handles MyBase.Paint
        e.Graphics.RotateTransform(20)
        e.Graphics.DrawString("Hello World!", Me.Font, Brushes.Blue, 0, 0)
    End Sub
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question