By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,732 Members | 824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,732 IT Pros & Developers. It's quick & easy.

rotate gdi object

P: n/a
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

--
-iwdu15
Jan 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
------------------------
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:20**********************************@microsof t.com...
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

--
-iwdu15

Jan 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.