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
Printable View
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
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
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 ? :ehh:
here it is with better commenting:
vb Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Static angle As Integer = 0 angle += 5 Dim r As New RectangleF(51, 51, 51, 51) 'left,top,width,height of picturebox 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 m.RotateAt(angle Mod 360, New PointF(26, 26)) 'rotate (angle Mod 360) degrees clockwise around centre pixel of picturebox Dim path As New Drawing.Drawing2D.GraphicsPath path.AddRectangle(r) path.Transform(m) Dim p(3) As Point Dim pp() As PointF = path.PathPoints Dim leftOffset As Single = 0 If path.GetBounds.X < 0 Then leftOffset = Math.Abs(path.GetBounds.X) If path.GetBounds.X > 0 Then leftOffset = -path.GetBounds.X Dim topOffset As Single = 0 If path.GetBounds.Y < 0 Then topOffset = Math.Abs(path.GetBounds.Y) If path.GetBounds.Y > 0 Then topOffset = -path.GetBounds.Y For x As Integer = 0 To 3 p(x).X = CInt(pp(x).X + leftOffset) p(x).Y = CInt(pp(x).Y + topOffset) Next Dim newPath As New Drawing.Drawing2D.GraphicsPath newPath.AddPolygon(p) 'left + centre of picturebox - 1/2 bounds.width, top + centre of picturebox - 1/2 bounds.height PictureBox1.Location = New Point(77 - CInt(newPath.GetBounds.Width / 2), 77 - CInt(newPath.GetBounds.Height / 2)) PictureBox1.Size = Rectangle.Round(newPath.GetBounds).Size PictureBox1.Region = New Region(newPath) Application.DoEvents() End Sub