Try this
Dim myMatrix As New Matrix
Dim myInvMatrix As New Matrix
Dim rect As New Rectangle(120, 50, 140, 50)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim rotatePoint As New PointF(190.0F, 75.0F)
myMatrix.RotateAt(45, rotatePoint)
myInvMatrix.RotateAt(45, rotatePoint)
myInvMatrix.Invert()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
TransformVectorsExample(e)
End Sub
Public Sub TransformVectorsExample(ByVal e As PaintEventArgs)
Dim myPen As New Pen(Color.Blue, 1)
Dim myPen2 As New Pen(Color.Red, 1)
Static Dim colorIdx As New Integer
e.Graphics.DrawRectangle(myPen, rect)
e.Graphics.Transform = myMatrix
If colorIdx = 0 Then
colorIdx = 1
e.Graphics.FillRectangle(Brushes.Blue, rect)
Else
colorIdx = 0
e.Graphics.FillRectangle(Brushes.Red, rect)
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim region As New Region
Dim polygon_path As New GraphicsPath(FillMode.Winding)
polygon_path.AddRectangle(rect)
polygon_path.Transform(myMatrix)
Dim polygon_region = New Region(polygon_path)
Dim pt As PointF() = {New PointF(e.X, e.Y)}
myInvMatrix.TransformPoints(pt)
If (rect.Contains(pt(0).X, pt(0).Y)) Then
Label1.Text = "in side"
Invalidate(polygon_region)
Else
Label1.Text = ""
End If
End Sub |