Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form with a picture and a button. I want to each time click on button, picture will rotate 30 degree.I found in internet but there is not.Usually they use 2 picture but I only use 1 picture.

If you know, please help me.

thanks for advance
Updated 21-Mar-11 0:05am

Did you already have a look at this excellent article: Image Transition in VB.NET Windows Forms[^]
Share this answer
[no name] 21-Mar-11 5:31am    
5+For link of such a excellent application.
Sergey Alexandrovich Kryukov 21-Mar-11 5:39am    
I don't think you voted.
Wendelius 21-Mar-11 5:51am    
Funny that I received an email since you replied to santosh's post. Do you know if this is the expected behaviour (all replies on ones solutions are sent to the person who originally posted the solution)?
Sergey Alexandrovich Kryukov 21-Mar-11 5:53am    
As far as I can understand, yes (and this is reasonable). Not sure about other cases.
Wendelius 21-Mar-11 5:55am    
I agree, it makes sense. I was just little surprised since the behaviour differs from the forums, but then again that makes sense also :)
you can use matrices wich found in :
I wrote this example for you it can help:
create new form and add a button named as button1 then write the folowing
Public Class Form1
    Dim gr As Graphics
    Dim mat As New Drawing2D.Matrix
    Dim im As Image
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As  _
System.EventArgs) Handles Me.Load
        ' create your graphics object using this method
        gr = Me.CreateGraphics
        im = Image.FromFile("Write your Image directory here")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  _
System.EventArgs) Handles Button1.Click
        'rotate matrix around specific point
        mat.RotateAt(30, New Point(100, 200))
        gr.Transform = mat
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As  _
 System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        'very important to clear your device before drawing, choose any color to clear it
        'image center match the rotation center
        gr.DrawImage(im, 75, 175, 50, 50)
    End Sub
End Class

you can have a look in my tutorial in directX transformation , i know it s different but you can get some usefull ideas Basic Directx Transformation with VB.NET
Share this answer
Dalek Dave 22-Mar-11 10:04am    
Good Answer
Abudreas 22-Mar-11 10:10am    
thanks anybody. I found the best way to resolve my problem and I think it is good.

Public Function RotateImg(ByVal bmpimage As Bitmap, ByVal angle As Single) As Bitmap
        Dim w As Integer = bmpimage.Width
        Dim h As Integer = bmpimage.Height
        Dim pf As PixelFormat = Nothing
        pf = bmpimage.PixelFormat
        Dim tempImg As New Bitmap(w, h, pf)
        Dim g As Graphics = Graphics.FromImage(tempImg)
        g.DrawImageUnscaled(bmpimage, 1, 1)
        Dim path As New GraphicsPath()
        path.AddRectangle(New RectangleF(0.0F, 0.0F, w, h))
        Dim mtrx As New Matrix()
        'Using System.Drawing.Drawing2D.Matrix class
        Dim rct As RectangleF = path.GetBounds(mtrx)
        Dim newImg As New Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf)
        g = Graphics.FromImage(newImg)
        g.TranslateTransform(-rct.X, -rct.Y)
        g.InterpolationMode = InterpolationMode.HighQualityBilinear
        g.DrawImageUnscaled(tempImg, 0, 0)
        Return newImg
    End Function

call this function:

Dim img As Bitmap
img = New Bitmap(My.Resources.bg4)
PictureBox1.Image = RotateImg(img, Convert.ToSingle(iAngel))
Share this answer
lsh2138 25-Oct-12 2:15am    
Share this answer
Sergey Alexandrovich Kryukov 21-Mar-11 5:54am    
*Much* more than enough, my 5.
Abhinav S 21-Mar-11 5:57am    
Thank you.
Wendelius 21-Mar-11 6:03am    
Extensive collection +5.
Abhinav S 21-Mar-11 6:03am    
Dalek Dave 22-Mar-11 10:04am    
Good links, 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900