Private Sub FrameOfClock(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim brPenBrush As New System.Drawing.Drawing2D.HatchBrush(HatchStyle, _
Frame_ForeColor, Frame_BackColor)
If Frame_Thickness <= 0 Then
brPenBrush = New System.Drawing.Drawing2D.HatchBrush(HatchStyle, _
Color.Transparent, Color.Transparent)
End If
Dim MyBrushPen As New Pen(brPenBrush)
MyBrushPen.Width = FrameWidth
Rect.Width = Me.Width
Rect.Height = Me.Height
Rect.X = 0
Rect.Y = 0
If Frame_Mode = F_Mode.QuadrAngular Then
e.Graphics.DrawRectangle(MyBrushPen, Rect)
Else
e.Graphics.DrawEllipse(MyBrushPen, Rect)
End If
End Sub
Private Sub ImageOfFrame(ByVal e As System.Windows.Forms.PaintEventArgs)
If Frame_Thickness <= 0 Then Me.FrameOfClock(e) : Exit Sub
Dim ExcludRect As New Rectangle(FrameWidth / 2, FrameWidth / 2, _
Me.Width - FrameWidth, Me.Height - FrameWidth)
Path.Reset()
If Frame_Mode = F_Mode.QuadrAngular Then
Path.AddRectangle(ExcludRect)
Else
Path.AddPie(ExcludRect, 0, 360)
End If
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
Rect.Width = Me.Width + 1
Rect.Height = Me.Height + 1
Rect.X = 0
Rect.Y = 0
e.Graphics.DrawImage(Frame_Image, Rect)
e.Graphics.ResetClip()
End Sub
Private Sub FirstExcluding(ByVal e As System.Windows.Forms.PaintEventArgs)
'Excluding Area
Rect.Width = ((Me.Width - 1) * (90 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (90 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.Reset()
Path.AddPie(Rect, 0, 360)
Rect.Width = ((Me.Width - 1) * (95 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (95 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.AddPie(Rect, 0, 360)
Rect.Width = (Me.Width - 1) + 200
Rect.Height = (Me.Height - 1) + 200
Rect.X = -100
Rect.Y = -100
Path.AddPie(Rect, 0, 360)
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
End Sub
Private Sub NextExcluding(ByVal e As System.Windows.Forms.PaintEventArgs)
'Excluding Area
Rect.Width = ((Me.Width - 1) * (85 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (85 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.Reset()
Path.AddEllipse(Rect)
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
End Sub
Private Sub HandOfSecond(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه ثانیه شمار
e.Graphics.Transform = MatrixSec
e.Graphics.DrawLine(PenSec, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 30) + (FrameWidth \ 2))
End Sub
Private Sub HandOfMinute(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه دقیقه شمار
e.Graphics.Transform = MatrixMin
e.Graphics.DrawLine(PenMin, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 10) + (FrameWidth \ 2))
End Sub
Private Sub HandOfHour(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه ساعت شمار
e.Graphics.Transform = MatrixHour
e.Graphics.DrawLine(PenHour, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 5) + (FrameWidth \ 2))
End Sub
Private Sub DrawClock(ByVal e As System.Windows.Forms.PaintEventArgs)
If Frame_Image Is Nothing Then
FrameOfClock(e)
Else
ImageOfFrame(e)
End If
'Excluding 1
FirstExcluding(e)
'Draw All Minute
Rect.Width = (Me.Width - 1) + 100
Rect.Height = (Me.Height - 1) + 100
Rect.X = -50
Rect.Y = -50
If Show_Minutes = True Then
For i As Integer = 0 To 360 Step 6
e.Graphics.DrawPie(New Pen(Me.ForeColor, Me.Width / 400), Rect, i, 6)
Next
End If
'Bold Hour 1,2,4,5,7,8,10,11
If Show_Hours = True Then
Dim MatrixTemp As New System.Drawing.Drawing2D.Matrix
For i As Integer = 0 To 360 Step 30
If i Mod 90 <> 0 And i > 0 Then
MatrixTemp.RotateAt(30, New Point(Me.Width \ 2, Me.Height \ 2))
e.Graphics.Transform = MatrixTemp
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), (Me.Width \ 2), 0, (Me.Width \ 2), Me.Height)
Else
If i > 0 Then MatrixTemp.RotateAt(30, New Point(Me.Width \ 2, Me.Height \ 2))
End If
Next
MatrixTemp.Dispose()
e.Graphics.Transform = New System.Drawing.Drawing2D.Matrix
End If
'Excluding 1
NextExcluding(e)
'Bold Hour 12 , 3 , 6 , 9
If Show_Hours = True Then
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), _
(Me.Width \ 2), FrameWidth \ 2, (Me.Width \ 2), Me.Height - (FrameWidth \ 2))
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), _
(FrameWidth \ 2), Me.Height \ 2, Me.Width - (FrameWidth \ 2), Me.Height \ 2)
End If
e.Graphics.ResetClip()
If Show_Digits = True Then Numbers(e)
DrawText(e)
If Digital_Clock = True Then DigTime(e)
If Show_Date = True Then DrawDate(e)
'Hands
If Hour_Hand = True Then HandOfHour(e)
If Minute_Hand = True Then HandOfMinute(e)
If Second_Hand = True Then HandOfSecond(e)
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
sec = Now.Second
MatrixSec.Reset()
MatrixSec.RotateAt((sec) * 6, New Point(Me.Width \ 2, Me.Height \ 2))
Min = Now.Minute
MatrixMin.Reset()
MatrixMin.RotateAt((sec * 0.1) + (Min * 6), New Point(Me.Width \ 2, Me.Height \ 2))
Hour = Now.Hour
If Hour > 12 Then Hour -= 12
MatrixHour.Reset()
MatrixHour.RotateAt((sec * 0.0083) + (Min * 0.5) + (Hour * 30), _
New Point(Me.Width \ 2, Me.Height \ 2))
Me.Invalidate()
If EventHour <> Now.Hour Then
RaiseEvent HourChanged()
EventHour = Now.Hour
ElseIf EventMin <> Now.Minute Then
RaiseEvent MinuteChanged()
EventMin = Now.Minute
Else
RaiseEvent SecondChanged()
End If
End Sub
Private Sub UserControl1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.SizeChanged
If Me.Width > Me.Height Then
Me.Height = Me.Width
ElseIf Me.Height > Me.Width Then
Me.Width = Me.Height
End If
SetRegion()
FrameWidth = (Me.Width) * (Frame_Thickness / 100)
PenSec.Width = Me.Width / 100
PenMin.Width = Me.Width / 55
PenHour.Width = Me.Width / 35
sec = Now.Second
Min = Now.Minute
Hour = Now.Hour
If Hour > 12 Then Hour -= 12
MatrixSec.Reset()
MatrixSec.RotateAt((sec) * 6, New Point(Me.Width \ 2, Me.Height \ 2))
Min = Now.Minute
MatrixMin.Reset()
MatrixMin.RotateAt((sec * 0.1) + (Min * 6), New Point(Me.Width \ 2, Me.Height \ 2))
MatrixHour.Reset()
MatrixHour.RotateAt((sec * 0.0083) + (Min * 0.5) + (Hour * 30), _
New Point(Me.Width \ 2, Me.Height \ 2))
End Sub
End Class