rotate gdi object

G

Guest

hi, im trying to rotate a gdi drawn object on my form with a
keypress....forinstance when i push the down arrow, for it to rotate the
object drawn until the top is down, or if i push the right arrow key, to
rotate the object until its pointed to the right. i tried using a drawing
matrix to accomplish this, but all it did was rotate my entire form (im
drawing my object on the back of the form) and thats not what i need. I need
it to rotate on the spot, so i tried RotateAt but that also didnt work...how
can i accomplish what im looking for?

thanks
 
K

Ken Tucker [MVP]

Hi,

Maybe this will help. I added a picturebox to a form and have it
draw an image in the paint event. The point that the image is rotated about
is the center of the image. I added a timer so every 100 miliseconds it
redraws the image rotated 30 degrees.

Imports System.Drawing.Drawing2D

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub


Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Static bm As Bitmap
Static intAngle As Integer = 0

If bm Is Nothing Then
bm = New Bitmap(16, 16)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
g.DrawLine(Pens.Red, 0, 0, 16, 16)
g.DrawLine(Pens.Blue, 0, 16, 16, 0)
End If

e.Graphics.TranslateTransform(50, 50)
e.Graphics.RotateTransform(intAngle)

e.Graphics.DrawImage(bm, -8, -8)
intAngle += 30
If intAngle > 360 Then intAngle -= 360
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
PictureBox1.Invalidate()
End Sub
End Class


Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top