Hi @Mansour_Dalir ,
You can calculate the points for each hour groove using trigonometric functions, then calculate the angle of the mouse pointer relative to the center of the clock. Check which groove the mouse is currently over and highlights it by drawing a thicker, green line. Other grooves are drawn with a default, thinner yellow line.
Imports System.Drawing
Imports System.Windows.Forms
Public Class MenuTimeSelector
Dim listPoint As New List(Of Point)
Dim CurrentPoint As New Point
Public Menu As New ContextMenuStrip
Dim WithEvents pnl As New Panel With {.BackgroundImage = My.Resources.TimeSelector, .BackgroundImageLayout = ImageLayout.Center}
Dim pen As New Pen(Color.Black)
Dim centerX As Integer
Dim centerY As Integer
Public Sub New()
pnl.Margin = New Padding(0)
Dim tlHost As New ToolStripControlHost(pnl) With {.AutoSize = False}
Menu.ShowImageMargin = False
Menu.DropShadowEnabled = False
Menu.ShowCheckMargin = False
Menu.Padding = New Padding(0)
Menu.Items.Add(tlHost)
centerX = pnl.BackgroundImage.Width / 2
centerY = pnl.BackgroundImage.Height / 2
End Sub
Private Sub pnl_MouseMove(sender As Object, e As MouseEventArgs) Handles pnl.MouseMove
Dim points = New Point(11) {}
Dim radius = 39
For i = 0 To 11
Dim angle_deg As Double = 30 + i * 30
Dim angle_rad = Math.PI / 180 * angle_deg
Dim x As Integer = centerX + radius * Math.Cos(angle_rad)
Dim y As Integer = centerY + radius * Math.Sin(angle_rad)
points(i) = New Point(x, y)
Next
Dim g As Graphics = pnl.CreateGraphics()
g.Clear(pnl.BackColor)
g.DrawImage(pnl.BackgroundImage, New PointF(0, 0))
Dim center As New Point(centerX, centerY)
Dim angle As Double = Math.Atan2(e.Y - center.Y, e.X - center.X) * 180 / Math.PI
While angle < 0
angle += 360
End While
Dim OffsetH As Integer = 11
Dim MouseOnTime As Integer = angle / 30
MouseOnTime = (MouseOnTime + OffsetH) Mod 12
For a = 0 To points.Length - 1
If a = MouseOnTime Then
CurrentPoint = points(a)
Dim grooveBounds As New Rectangle(points(a).X - 9, points(a).Y - 9, 18, 18)
g.DrawEllipse(New Pen(Color.Green, 2), grooveBounds)
g.DrawLine(New Pen(Color.Green, 2), center, points(a)) ' Highlight the groove
Else
g.DrawLine(New Pen(Color.Yellow, 1), center, points(a)) ' Default groove color
End If
Next
Using pen1 As New Pen(Color.Lime, 3)
For Each poi In listPoint
g.DrawLine(pen1, center, poi)
Next
End Using
End Sub
Private Sub pnl_MouseClick(sender As Object, e As MouseEventArgs) Handles pnl.MouseClick
listPoint.Add(CurrentPoint)
End Sub
End Class
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.