Google Answers Logo
View Question
 
Q: How to detect whether cursor is over a Rotated/Translated Rectangle in .NET ( No Answer,   2 Comments )
Question  
Subject: How to detect whether cursor is over a Rotated/Translated Rectangle in .NET
Category: Computers > Programming
Asked by: brother_bill-ga
List Price: $25.00
Posted: 16 Mar 2005 16:10 PST
Expires: 20 Mar 2005 12:50 PST
Question ID: 495844
Detecting MouseMove for Rotated Rectangle in .net using Winforms application.
The goal is to display a rotated rectangle, text, image or ellipse, etc.,
(which I know how to do)
and have a hit-test that would indicate whether a particular screen pixel,
such as from onMouseMove Event, which would indicate whether the cursor
is over the Rotated and Translated Rectangle (I don't know how to do this)

The figures (shapes) are drawn directly on the Form.

As a secondary (included) question, I would like to know how to
invalidate just the rotated translated rectangle.

Would want code sample in VB.net (C# would also be ok) that exercises this feature.

Clarification of Question by brother_bill-ga on 16 Mar 2005 16:11 PST
I am hoping that there is a simple way to do this, such as
somePath.contains (screenPoint)
Answer  
There is no answer at this time.

Comments  
Subject: Re: How to detect whether cursor is over a Rotated/Translated Rectangle in .NET
From: crythias-ga on 18 Mar 2005 13:14 PST
 
If you're using HTML, you could put an <a href="#"> </a> around your image.
Further, you could use an image map for a more discreet way. <img
src="myrotatedpic.jpg" usemap="mymap">

Of course at that point you can put your OnMouseOver scripts.
--
This is a free comment.
Subject: Re: How to detect whether cursor is over a Rotated/Translated Rectangle in .NET
From: marimomo-ga on 19 Mar 2005 00:10 PST
 
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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy