|
-
Aug 24th, 2008, 10:39 PM
#1
Thread Starter
Member
Rotating a Picturebox.
Hey, I am creating an Advanced menu DLL, But how can i Rotate a Picturebox so that the Top is Pointing towards the Mouse Cursor?
Possible?
- Cheers
uhm, it wasn't me..
Prove it..
Prove it was me........
-
Aug 24th, 2008, 10:51 PM
#2
Re: Rotating a Picturebox.
You can't. If you want to display an image rotated then you'll need to draw it using GDI+. In the Paint event of your form, or whatever control you want to draw on, use the RotateTransform method to rotate the Graphics object's frame of reference before calling DrawImage.
You might want to call TranslateTransform too, to make the centre of the image the origin. That makes positioning the Image easier.
-
Aug 24th, 2008, 10:58 PM
#3
Thread Starter
Member
Re: Rotating a Picturebox.
Could you help me out there? I added that code..But im not Sure how to go about using it..Im new to GDI...
My Control to use is the Form...
- Cheers
uhm, it wasn't me..
Prove it..
Prove it was me........
-
Aug 24th, 2008, 11:21 PM
#4
Re: Rotating a Picturebox.
Create a new WinForms project.
Add a NumericUpDown and a Button.
Set the NUD's Minimum and Maximum to 0 and 359 respectively.
Add the following code:
Code:
Private img As Image = Image.FromFile("file path here")
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
Me.Refresh()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As PaintEventArgs) Handles Me.Paint
With e.Graphics
'Shift the origin to the centre of the form.
.TranslateTransform(Me.ClientSize.Width \ 2, Me.ClientSize.Height \ 2)
'Rotate the frame of refence.
.RotateTransform(CInt(Me.NumericUpDown1.Value))
'Position the image so that it is concentric with the form.
Dim bounds As Rectangle = New Rectangle(-Me.img.Width \ 2, _
-Me.img.Height \ 2, _
Me.img.Width, _
Me.img.Height)
'Draw the image.
.DrawImage(Me.img, bounds)
End With
End Sub
Insert your own image path.
Run the project and try changing the angle in the NUD and clicking the Button.
That shows you how to draw an image using a specific rotation. When you choose to set that angle and redraw the Image is up to you. Note that it is generally preferable to call Invalidate and Update rather than Refresh, so as to keep the area that gets redrawn to a minimum.
-
May 19th, 2009, 09:40 PM
#5
Fanatic Member
Re: Rotating a Picturebox.
 Originally Posted by jmcilhinney
Create a new WinForms project.
Add a NumericUpDown and a Button.
Set the NUD's Minimum and Maximum to 0 and 359 respectively.
Add the following code:[CODE]Private img As Image = Image.FromFile("file path here")
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
Me.Refresh()
End Sub
.
i think Jm has a bit confuse in here. the event should have be :
Code:
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles NumericUpDown1.ValueChanged
Me.Refresh()
End Sub
-
May 19th, 2009, 09:47 PM
#6
Re: Rotating a Picturebox.
 Originally Posted by manhit45
i think Jm has a bit confuse in here. the event should have be :
Code:
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles NumericUpDown1.ValueChanged
Me.Refresh()
End Sub
Um, no, I'm not confused at all. Did you read what I posted?
Run the project and try changing the angle in the NUD and clicking the Button.
If you handle the ValueChanged event of the NUD then every time you change the value in the NUD the form will get repainted. If the NUD currently shows 10 and you press and hold its UP button then its Value will be incremented repeatedly. You're hardly going to want the form to repaint on every one of those changes. You would wait until you have reached your intended final value, then explicitly force a repaint by clicking the Button.
-
May 19th, 2009, 10:00 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|