Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Mouse Hover over round Area?

1 view
Skip to first unread message

Cor Ligthert

unread,
Sep 21, 2004, 3:49:32 AM9/21/04
to
Lars,

Did you ever see this nice sample I once have made in the past?

It should have parts of your question.
(it needs only a form and paste the code in)

I hope you can use it?

Cor

\\\made by Cor Ligthert from ideas I got from Herfried. K. Wagner and Fergus
Cooney
Private WithEvents button1 As New Button
Private mouseX, mouseY As Integer
Private myMouseDown As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim g As New System.Drawing.Drawing2D.GraphicsPath
g.AddString("HTH" & vbCrLf & "Cor", _
System.Drawing.FontFamily.GenericSansSerif, _
System.Drawing.FontStyle.Bold, 200, _
New Point(0, 0), _
System.Drawing.StringFormat.GenericDefault)
Me.BackColor = Color.Red
Me.Region = New System.Drawing.Region(g)
g.Dispose()
Me.AutoScaleBaseSize = New System.Drawing.Size(0, 0)
Me.ClientSize = New System.Drawing.Size(500, 450)
button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
button1.ForeColor = System.Drawing.Color.Black
button1.Location = New System.Drawing.Point(425, 18)
button1.Size = New System.Drawing.Size(20, 20)
Me.Controls.Add(button1)
button1.Text = "X"
Me.Location = New System.Drawing.Point(50, 50)
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles button1.Click
Me.Close()
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal _
e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
myMouseDown = True
mouseX = Cursor.Position.X - Me.Location.X
mouseY = Cursor.Position.Y - Me.Location.Y
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Position.X,
Cursor.Position.Y)
If Point.op_Inequality(NowCursor, LastCursor) Then
If myMouseDown Then
Me.Location = New System.Drawing.Point(Cursor.Position.X _
- mouseX, Cursor.Position.Y - mouseY)
End If
LastCursor = Cursor.Position
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
myMouseDown = False
End Sub
///


"Lars Netzel" <[stop_spam]@host.topdomain>
> Hi!
>
> I have a round area which I want to be able to move the mouse over and
fire
> off events... how do I do that?
>
> I have drawn a FillPie Graphics and I feel that there has to be a way of
> getting to know if the mouse is over that area since I have the
coordinates
> to paint the Pie but I don't know where to start or what to look for
really.
>
> Best Regard
> /Lars
>
>


One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 5:15:49 AM9/21/04
to
No the answer is easier than that.


You take the centre of the client area and compute.

For example, if the radius is 10 your client area is 20,20. Then the
centre point is 10,10. If x, or y is larger than the centre point + or -
the mouse coordinates then this is out

Alternatively calculate the hypotenuse for any given point


H*H = A*A + O*O

Once you calculate the H = SQRT( A*A + O*O) you can compare this against the
Radius. to determin if the point is in.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:O%23z$aT7nEH...@TK2MSFTNGP11.phx.gbl...
> Yes, it helps a little to understand how to get the posistion of the mouse
> Cursor and compare with that op_Inequality but I'm not sure how to get the
> position to compare with... I mean, if I have the mouseCursor.. Do I need
to
> loop thru all the points within the Round Area and run the op_inequality
> test then, and how to I get the points for that Area...?
>
> /Lars
>
>
>
>
>
>
> "Cor Ligthert" <notfir...@planet.nl> skrev i meddelandet
> news:uQzUO%236nEH...@TK2MSFTNGP09.phx.gbl...

Ken Tucker [MVP]

unread,
Sep 21, 2004, 6:42:07 AM9/21/04
to
Hi,

Dim rgnCircle As Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim pth As New System.Drawing.Drawing2D.GraphicsPath

pth.AddEllipse(100, 100, 50, 50)

rgnCircle = New Region(pth)

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

e.Graphics.FillRegion(Brushes.Blue, rgnCircle)

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Me.Text = String.Format("In Circle {0}", rgnCircle.IsVisible(New Point(e.X,
e.Y)))

End Sub

Ken

---------------------------

"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message

news:eF4Ja36n...@tk2msftngp13.phx.gbl...

Ken Tucker [MVP]

unread,
Sep 21, 2004, 6:44:47 AM9/21/04
to
Hi,

Wouldnt region.isvisible be easier?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingregionclassisvisibletopic.asp


Ken
---------------------
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uMRout7n...@TK2MSFTNGP11.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 7:10:08 AM9/21/04
to
I tested this , it may not be the most efficient, but it works

Private cp As Point

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Graphics

g = pBox.CreateGraphics

cp = New Point(pBox.Size.Width / 2, pBox.Size.Height / 2)

g.DrawEllipse(New Pen(Color.Red), New Rectangle(cp.X - 10, cp.Y -
10, 20, 20))

End Sub

Private Sub pBox_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pBox.MouseMove

Dim rx As Single = 10
Dim ry As Single = 10
Dim distance As Single 'between centre and mouse position
Dim a, h, o As Single

If e.X = cp.X And e.Y = cp.Y Then ' Same Point
distance = 0
ElseIf e.X = cp.X Then 'Horizontal line
distance = Math.Abs(e.X - cp.X)
ElseIf e.Y = cp.Y Then 'Virtical Line
distance = Math.Abs(e.Y - cp.Y)
Else 'This is a triangle, so calculate the hypotenuse
a = Math.Abs(e.X - cp.X)
o = Math.Abs(e.Y - cp.Y)
h = Math.Sqrt(a ^ 2 + o ^ 2)
distance = h
End If
'Debug.WriteLine("Distance : " & distance & " : " & cp.ToString)
If distance < 10 Then ' this is inside the circle so
Debug.WriteLine(e.X & " : " & e.Y)
End If

End Sub

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:O%23z$aT7nEH...@TK2MSFTNGP11.phx.gbl...
> Yes, it helps a little to understand how to get the posistion of the mouse
> Cursor and compare with that op_Inequality but I'm not sure how to get the
> position to compare with... I mean, if I have the mouseCursor.. Do I need
to
> loop thru all the points within the Round Area and run the op_inequality
> test then, and how to I get the points for that Area...?
>
> /Lars
>
>
>
>
>
>
> "Cor Ligthert" <notfir...@planet.nl> skrev i meddelandet
> news:uQzUO%236nEH...@TK2MSFTNGP09.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 8:03:21 AM9/21/04
to
Yes but this is a circle, what you refer to is a rectangle test. I think the
OP wanted to only fire events or trigger action at least when the mouse was
inside a defined pie chart or ( circle )

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Ken Tucker [MVP]" <vb...@bellsouth.net> wrote in message
news:euDzHg8n...@TK2MSFTNGP10.phx.gbl...

Jay B. Harlow [MVP - Outlook]

unread,
Sep 21, 2004, 9:36:29 AM9/21/04
to
OHM,
But a Region (GraphicsPath really) can be circular!

Dim path As New System.Drawing.Drawing2D.GraphicsPath()
path.AddEllipse(aRectangle)


So you could use either Region.IsVisible or GraphicsPath.IsVisible.

Borrowing your earlier code (untested):

> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim g As Graphics
>
> g = pBox.CreateGraphics
>
> cp = New Point(pBox.Size.Width / 2, pBox.Size.Height / 2)
>
> g.DrawEllipse(New Pen(Color.Red), New Rectangle(cp.X - 10, cp.Y -
> 10, 20, 20))
>
>
>
> End Sub
>

> Private Sub pBox_MouseMove(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles pBox.MouseMove
>
Dim path As New System.Drawing.Drawing2D.GraphicsPath
Dim cp As New Point(pBox.Size.Width / 2, pBox.Size.Height / 2)

path.AddEllipse(New Rectangle(cp.X - 10, cp.Y - 10, 20, 20))

If path.IsVisible(e.X, e.Y) Then

Debug.WriteLine(e.X & " : " & e.Y)

End If

>
> End Sub


I would probably keep a class instance variable for the outline of the image
being checked, the GraphicsPath above, then I would simply use this variable
in the MouseMove & Paint events. Depending on what the "area" is really that
the OP is wanting I would consider creating a derived control & set its
Control.Region property to the shape desired (a round Button or round Label
for example).

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message

news:%23oVJWL9...@TK2MSFTNGP11.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 10:21:03 AM9/21/04
to
Good stuff !, thats illuminating, its allways good to learn something new.!

Thanks

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Jay_Har...@msn.com> wrote in message
news:etPFJA%23nEH...@TK2MSFTNGP15.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 10:24:01 AM9/21/04
to
My Mistake,

Ken you were right and I was wrong.

Thanks

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Ken Tucker [MVP]" <vb...@bellsouth.net> wrote in message
news:euDzHg8n...@TK2MSFTNGP10.phx.gbl...

Jay B. Harlow [MVP - Outlook]

unread,
Sep 21, 2004, 11:00:26 AM9/21/04
to
OHM,
I would not (did not) say your were wrong! :-)

IMHO there are at least 3 ways to do every thing.

You just had a different way of seeing the problem & solving it. I used
GraphicsPath, Ken suggested Region. I also suggested creating a circular
control. I'm sure there are others, at least variations of what we all
suggested.

In case you were wondering to get a circular Region you need to start with a
circular GraphicsPath, which you pass to the constructor of the Region.

Just a thought
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message

news:eewi8Z%23nEH...@TK2MSFTNGP11.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Sep 21, 2004, 11:42:03 AM9/21/04
to
No worries, thanks Jay.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Jay_Har...@msn.com> wrote in message
news:OL2TDv%23nEH...@TK2MSFTNGP15.phx.gbl...

0 new messages