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 :)
Printable View
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 :)
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.
Could you help me out there? :thumb: 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
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:Insert your own image path.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
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.
Um, no, I'm not confused at all. Did you read what I posted?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.Quote:
Run the project and try changing the angle in the NUD and clicking the Button.
oK , I am confuse myself. sorrrrrrrrrry:confused: :bigyello:
(in my case when NUD change the angle change correlatively with value of NUD.)