📄 form1.vb
字号:
Case 10, 11, 12, 39, 40
Dim srcRect As New Rectangle(15 * 7, 0, 540 - 15 * 7, 184)
Dim rec As New Rectangle(540, 0, 15 * 7, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 7, 0, rec, units)
Case 13, 14, 41
Dim srcRect As New Rectangle(15 * 8, 0, 540 - 15 * 8, 184)
Dim rec As New Rectangle(540, 0, 15 * 8, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 8, 0, rec, units)
Case 15, 42, 43
Dim srcRect As New Rectangle(15 * 8 + 7, 0, 540 - 15 * 8 - 7, 184)
Dim rec As New Rectangle(540, 0, 15 * 8 + 7, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 8 - 7, 0, rec, units)
Case 16, 17, 44, 45, 46
Dim srcRect As New Rectangle(15 * 9, 0, 540 - 15 * 9, 184)
Dim rec As New Rectangle(540, 0, 15 * 9, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 9, 0, rec, units)
Case 18, 47
Dim srcRect As New Rectangle(15 * 10, 0, 540 - 15 * 10, 184)
Dim rec As New Rectangle(540, 0, 15 * 10, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 10, 0, rec, units)
Case 19, 48, 49
Dim srcRect As New Rectangle(15 * 11, 0, 540 - 15 * 11, 184)
Dim rec As New Rectangle(540, 0, 15 * 11, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 11, 0, rec, units)
Case 20, 21
Dim srcRect As New Rectangle(15 * 12, 0, 540 - 15 * 12, 184)
Dim rec As New Rectangle(540, 0, 15 * 12, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 12, 0, rec, units)
Case 22, 23, 24
Dim srcRect As New Rectangle(0, 0, 540, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
Case 25, 26, 27, 28, 29
Dim srcRect As New Rectangle(15, 0, 540 - 15, 184)
Dim rec As New Rectangle(540, 0, 15, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15, 0, rec, units)
Case 30, 31, 32
Dim srcRect As New Rectangle(15 * 2, 0, 540 - 15 * 2, 184)
Dim rec As New Rectangle(540, 0, 15 * 2, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 2, 0, rec, units)
Case 33
Dim srcRect As New Rectangle(15 * 3, 0, 540 - 15 * 3, 184)
Dim rec As New Rectangle(540, 0, 15 * 3, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 3, 0, rec, units)
Case 34
Dim srcRect As New Rectangle(15 * 3 + 7, 0, 540 - 15 * 3 - 7, 184)
Dim rec As New Rectangle(540, 0, 15 * 3 + 7, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 3 - 7, 0, rec, units)
Case 35
Dim srcRect As New Rectangle(15 * 4, 0, 540 - 15 * 4, 184)
Dim rec As New Rectangle(540, 0, 15 * 4, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 4, 0, rec, units)
Case 36
Dim srcRect As New Rectangle(15 * 4 + 7, 0, 540 - 15 * 4 - 7, 184)
Dim rec As New Rectangle(540, 0, 15 * 4 + 7, 184)
e.Graphics.DrawImage(My.Resources.timezone_map, 0, 0, srcRect, units)
e.Graphics.DrawImage(My.Resources.timezone_map, 540 - 15 * 4 - 7, 0, rec, units)
End Select
End Sub
Private Sub pbclock_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbclock.Paint
'画时钟
dMyDate = DateTime.Now
drawDotAtiMinutes(pbclock, e)
drawminhand(pbclock, e, dMyDate.Minute, 60)
drawminhand(pbclock, e, 5 * dMyDate.Hour, 40)
drawsechand(pbclock, e, dMyDate.Second, 60)
End Sub
Public Sub drawDotAtiMinutes(ByVal onObj As PictureBox, ByVal e As Windows.Forms.PaintEventArgs)
Const clockInset As Integer = 5 ' distance from clock edge to box edge
Dim dotRadius As Integer = 5 ' size of the dot
Dim smallDim As Integer ' smaller of width and height of box
Dim clockRadius As Integer ' radius of the clock
Dim centerX As Integer ' x for center of the clock
Dim centerY As Integer ' y for center of the clock
Dim x As Integer ' x position of dot
Dim y As Integer ' y position of dot
Dim brush As New SolidBrush(Color.Black) 'brush
Dim i As Integer
i = 0
Dim blueblush As New SolidBrush(Color.Blue)
' calculate the center of the clock and its radius so it fits in the box
centerX = onObj.Width / 2
centerY = onObj.Height / 2
smallDim = onObj.Width
If (onObj.Height < smallDim) Then
smallDim = onObj.Height
End If
clockRadius = smallDim / 2 - clockInset
' calculate the position of the dot
For i = 0 To 60
x = centerX + clockDrawX(i, clockRadius - dotRadius)
y = centerY + clockDrawY(i, clockRadius - dotRadius)
If i Mod 5 = 0 Then
e.Graphics.FillEllipse(blueblush, x, y, dotRadius, dotRadius)
Else
e.Graphics.FillEllipse(brush, x, y, 2, 2)
End If
Next i
End Sub
Public Function clockDrawX(ByVal minuteVal As Integer, ByVal radius As Integer)
Const PI As Double = 3.14159265
Dim angle As Double
angle = (PI * 2 * minuteVal) / 60 - PI / 2
Return CInt(radius * Math.Cos(angle))
End Function
Public Function clockDrawY(ByVal minuteVal As Integer, ByVal radius As Integer)
Dim angle As Double
Dim PI As Double
PI = 3.14159265
angle = (PI * 2 * minuteVal) / 60 - PI / 2
Return CInt(radius * Math.Sin(angle))
End Function
Public Sub drawminhand(ByVal onObj As PictureBox, ByVal e As Windows.Forms.PaintEventArgs, ByVal min As Integer, ByVal length As Integer)
'用多边形画分钟和时钟
Dim x1, y1, x2, y2, x3, y3, x4, y4 As Single
x1 = 80 + clockDrawX(min, length)
y1 = 80 + clockDrawY(min, length)
x2 = 80 + clockDrawX(min + 15, 5)
y2 = 80 + clockDrawY(min + 15, 5)
x3 = 80 + clockDrawX(min + 30, 10)
y3 = 80 + clockDrawY(min + 30, 10)
x4 = 80 + clockDrawX(min + 45, 5)
y4 = 80 + clockDrawY(min + 45, 5)
Dim blueblush As New SolidBrush(Color.DarkGreen)
Dim point1 As New PointF(x1, y1)
Dim point2 As New PointF(x2, y2)
Dim point3 As New PointF(x3, y3)
Dim point4 As New PointF(x4, y4)
Dim curvePoints As PointF() = {point1, point2, point3, point4}
e.Graphics.FillPolygon(blueblush, curvePoints)
End Sub
Public Sub drawsechand(ByVal onObj As PictureBox, ByVal e As Windows.Forms.PaintEventArgs, ByVal sec As Integer, ByVal length As Integer)
'用直线画秒钟
Dim x1, y1, x2, y2 As Integer
Dim pen As New Pen(Color.Black)
x1 = 80 + clockDrawX(sec, length)
y1 = 80 + clockDrawY(sec, length)
x2 = 80 + clockDrawX(sec + 30, 5)
y2 = 80 + clockDrawY(sec + 30, 5)
e.Graphics.DrawLine(pen, x1, y1, x2, y2)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'用Timer设置时间的更新
pbclock.Refresh()
Dim tnsecvalue As Int16
tnsecvalue = dMyDate.Hour
If tnsecvalue > 12 Then
tnsecvalue = tnsecvalue - 12
tbHour.Text = tnsecvalue.ToString()
Else
tbHour.Text = tnsecvalue.ToString()
End If
nnupHour.Value = Convert.ToInt16(tnsecvalue)
nnupMin.Value = Convert.ToInt16(dMyDate.Minute)
nnupSec.Value = Convert.ToInt16(dMyDate.Second)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -