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
>
>
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...
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...
Wouldnt region.isvisible be easier?
Ken
---------------------
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uMRout7n...@TK2MSFTNGP11.phx.gbl...
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...
--
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...
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...
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...
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...
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...
--
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...