Results 1 to 7 of 7

Thread: [RESOLVED] Rotate picturebox ? how can i

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Resolved [RESOLVED] Rotate picturebox ? how can i

    i was wondering if anyone can tell me how to rotate a picturebox , my picturebox wont have an image in it it' just colored in i want to rotate it a little cause im making a little game
    if anyone could help with this that would be great

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Rotate picturebox ? how can i

    You should always search the forum before posting.

    http://www.vbforums.com/showthread.php?t=537099
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Rotate picturebox ? how can i

    Quote Originally Posted by jmcilhinney View Post
    You should always search the forum before posting.

    http://www.vbforums.com/showthread.php?t=537099
    i did do that and thank's ,not trying to be rude but you should of read my post before posting xD i asked if i could rotate the picturebox not an image

    Edit:i just read one of your posts from 1 year ago and it said you can not rotate a picturebox or any windows controls
    Last edited by tweaker99; Aug 13th, 2010 at 03:13 AM.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Rotate picturebox ? how can i

    here's an example:
    Attached Files Attached Files

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Rotate picturebox ? how can i

    Quote Originally Posted by .paul. View Post
    here's an example:
    Thank you so much! that was exactly what i was looking for

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Rotate picturebox ? how can i

    Quote Originally Posted by .paul. View Post
    here's an example:
    sorry to bumbp this but with your code im having touble figuring it out , how can i have it keep the size of the picturebox ? like the size ie 51 already but if i make it say 101 it doesn't work , i edited the code and got it to kinda work but im still confused how could i have it automatically stay at the size and location i make it ?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Rotate picturebox ? how can i

    here it is with better commenting:

    vb Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.  
    3.     Static angle As Integer = 0
    4.  
    5.     angle += 5
    6.  
    7.     Dim r As New RectangleF(51, 51, 51, 51) 'left,top,width,height of picturebox
    8.     Dim m As New Drawing.Drawing2D.Matrix(r, New PointF() {New PointF(0, 0), New PointF(51, 0), New PointF(0, 51)}) 'points - topleft,topright,bottomleft of picturebox
    9.     m.RotateAt(angle Mod 360, New PointF(26, 26)) 'rotate (angle Mod 360) degrees clockwise around centre pixel of picturebox
    10.     Dim path As New Drawing.Drawing2D.GraphicsPath
    11.     path.AddRectangle(r)
    12.     path.Transform(m)
    13.  
    14.     Dim p(3) As Point
    15.     Dim pp() As PointF = path.PathPoints
    16.  
    17.     Dim leftOffset As Single = 0
    18.     If path.GetBounds.X < 0 Then leftOffset = Math.Abs(path.GetBounds.X)
    19.     If path.GetBounds.X > 0 Then leftOffset = -path.GetBounds.X
    20.     Dim topOffset As Single = 0
    21.     If path.GetBounds.Y < 0 Then topOffset = Math.Abs(path.GetBounds.Y)
    22.     If path.GetBounds.Y > 0 Then topOffset = -path.GetBounds.Y
    23.  
    24.     For x As Integer = 0 To 3
    25.         p(x).X = CInt(pp(x).X + leftOffset)
    26.         p(x).Y = CInt(pp(x).Y + topOffset)
    27.     Next
    28.  
    29.     Dim newPath As New Drawing.Drawing2D.GraphicsPath
    30.     newPath.AddPolygon(p)
    31.    
    32.     'left + centre of picturebox - 1/2 bounds.width, top + centre of picturebox - 1/2 bounds.height
    33.     PictureBox1.Location = New Point(77 - CInt(newPath.GetBounds.Width / 2), 77 - CInt(newPath.GetBounds.Height / 2))
    34.    
    35.     PictureBox1.Size = Rectangle.Round(newPath.GetBounds).Size
    36.  
    37.     PictureBox1.Region = New Region(newPath)
    38.  
    39.     Application.DoEvents()
    40.  
    41. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width