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.




Reply With Quote