I can move and resize an object with now issues finding the grab handles but when I rotate it using matrix transform the grab handles draw properly but but the points do not change the points are still where they where before rotating. I can seem to find a way to invalidate the transform so they match. I will post the code used below
This is the code to search for the rectangles its located in the Mouse move sub procedure
If e.Button = MouseButtons.Left Then
'Dim rectf As Rectangle = Rectangle.Round(gobjc.DragRectangleFangle)
gobjc.DragRectangleF = New RectangleF(SelectedObject.X, SelectedObject.Y, SelectedObject.Width, SelectedObject.Height)
StartlRectangle = gobjc.DragRectangleF
SelectedObject.AutoSize = False
If MouseInRect And ActiveDrag = -1 Then
RectDragging = True
MousePos = New Point(e.X, e.Y)
MousePos = PointToScreen(MousePos)
'OriginalRectangle = gobjc.DragRectangleFangle
ElseIf ActiveDrag <> -1 Then
RectResizing = True
MousePos = New Point(e.X, e.Y)
MousePos = PointToScreen(MousePos)
End If
End If
And the paint event code below
Public Sub DrawSelectedObject(ByVal g As Graphics, ByVal selectedObject As GraphicObjects, ByVal Scale As Single)
If selectedObject Is Nothing Then
Exit Sub
End If
Dim gCon1, gCon2 As Drawing2D.GraphicsContainer
gCon1 = g.BeginContainer
g.ScaleTransform(Scale, Scale,
Drawing.Drawing2D.MatrixOrder.Append)
gCon2 = g.BeginContainer
g.PageUnit = GraphicsUnit.Pixel
If Not selectedObject Is Nothing Then
Dim selectionPen As New Pen(Color.FromKnownColor(KnownColor.Black))
selectionPen.DashStyle = Drawing2D.DashStyle.Solid
selectionPen.Width = 1
Dim GrabHandleBrush As Brush = New SolidBrush(Color.Black)
Dim HandlePen As New Pen(Color.FromKnownColor(KnownColor.Black))
If selectedObject.Rotation <> 0 Then
Dim myMatrix As Drawing2D.Matrix
myMatrix = g.Transform()
myMatrix.RotateAt(selectedObject.Rotation, New PointF(selectedObject.X, selectedObject.Y), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
'RotatedBitmap = RotateImage(selectedObject.Image, selectedObject.Rotation)
End If
DragRectangleF = New RectangleF(selectedObject.X, selectedObject.Y, selectedObject.Width, selectedObject.Height)
Dim RectHeight As Integer = 8
If selectedObject.Height < 50 Then
RectHeight = 4
ElseIf selectedObject.Height < 25 Then
RectHeight = 2
End If
Drag_Handles(0) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(1) = New RectangleF(DragRectangleF.X + DragRectangleF.Width / 2 - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(2) = New RectangleF(DragRectangleF.X + DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(3) = New RectangleF(DragRectangleF.X + DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height / 2 - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(4) = New RectangleF(DragRectangleF.X + DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(5) = New RectangleF(DragRectangleF.X + DragRectangleF.Width / 2 - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(6) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(7) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height / 2 - RectHeight / 2, RectHeight, RectHeight)
'last 2 drag handles are for rotating object
Drag_Handles(8) = New RectangleF(DragRectangleF.X + DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y + 10, RectHeight, RectHeight)
Drag_Handles(9) = New RectangleF(DragRectangleF.X + DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y + DragRectangleF.Height - 20, RectHeight, RectHeight)
g.DrawRectangle(New Pen(Color.Gray), DragRectangleF.X, DragRectangleF.Y, DragRectangleF.Width, DragRectangleF.Height)
g.FillRectangles(Brushes.Gray, Drag_Handles)
g.DrawRectangles(Pens.Black, Drag_Handles)
Dim RotationDragHandle As New RectangleF()
RotationDragHandle = Drag_Handles(8)
g.FillRectangle(Brushes.YellowGreen, RotationDragHandle)
Dim RotationDragHandle1 As New RectangleF()
RotationDragHandle1 = Drag_Handles(9)
g.FillRectangle(Brushes.YellowGreen, RotationDragHandle1)
End If
g.EndContainer(gCon2)
g.EndContainer(gCon1)
End Sub
this is code for the paint event
Thanks in advance I hope I can figure this out.