📄 form1.vb
字号:
Public Class Form1
Const PI As Double = 3.14159265
Dim insetX, insetY, shapeWidth, shapeHeight As Integer
Dim shape As String
Dim year As String = Now().Year
Dim month As String = Now().Month
Dim day As String = Now().Day
Dim hour As String = Now().Hour
Dim min As String = Now().Minute
Dim sec As String = Now().Second
Dim itype As Integer
Dim watchTime As Integer = 0
Dim offset() As Integer = {-720, -660, -600, -540, -480, -420, -420, -360, -360, -360, -300, -300, -300, -240, -240, -210, -180, -180, -120, -60, +0, +0, +60, +60, +60, +120, +120, +120, +120, +120, +180, +180, +180, +240, +270, +300, +330, +360, +420, +480, +480, +540, +570, +570, +600, +600, +600, +660, +720, +720}
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
itype = MsgBox("OK..." + vbCrLf & "==================================" + vbCrLf & "Year=" + year + vbCrLf & "Month=" + month + vbCrLf & "Day=" + day + vbCrLf & "Hour=" + hour + vbCrLf & "Minute=" + min + vbCrLf & "Second=" + sec + vbCrLf & "Time Zone=" + ComboBox1.Text + vbCrLf & "Offset from GMT=" + CStr(offset(ComboBox1.SelectedIndex)) + " " + "minutes" + vbCrLf & "Auto daylight=" + CStr(CheckBox1.Enabled) + vbCrLf & "==================================" + vbCrLf & "(Time not saved)", MsgBoxStyle.OkOnly, "Exercise 5")
If (itype = MsgBoxResult.Ok) Then
Application.Exit()
End If
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
itype = MsgBox("OK..." + vbCrLf & "==================================" + vbCrLf & "Year=" + year + vbCrLf & "Month=" + month + vbCrLf & "Day=" + day + vbCrLf & "Hour=" + hour + vbCrLf & "Minute=" + min + vbCrLf & "Second=" + sec + vbCrLf & "Time Zone=" + ComboBox1.Text + vbCrLf & "Offset from GMT=" + CStr(offset(ComboBox1.SelectedIndex)) + " " + "minutes" + vbCrLf & "Auto daylight=" + CStr(CheckBox1.Enabled) + vbCrLf & "==================================" + vbCrLf & "(Time not saved)", MsgBoxStyle.OkOnly, "Exercise 5")
If (itype = MsgBoxResult.Ok) Then
Application.Exit()
End If
End Sub
Private Sub btnapply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnapply.Click
itype = MsgBox("OK..." + vbCrLf & "==================================" + vbCrLf & "Year=" + year + vbCrLf & "Month=" + month + vbCrLf & "Day=" + day + vbCrLf & "Hour=" + hour + vbCrLf & "Minute=" + min + vbCrLf & "Second=" + sec + vbCrLf & "Time Zone=" + ComboBox1.Text + vbCrLf & "Offset from GMT=" + CStr(offset(ComboBox1.SelectedIndex)) + " " + "minutes" + vbCrLf & "Auto daylight=" + CStr(CheckBox1.Enabled) + vbCrLf & "==================================" + vbCrLf & "(Time not saved)", MsgBoxStyle.OkOnly, "Exercise 5")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim i As Integer
PictureBox1.Refresh()
lblTimeZone.Text = "Current Time Zone:" + ComboBox1.Text
For i = 0 To 49
CheckBox1.Enabled = True
Next
Select Case (ComboBox1.SelectedIndex)
Case (0)
CheckBox1.Enabled = False
Case (1)
CheckBox1.Enabled = False
Case (2)
CheckBox1.Enabled = False
Case (5)
CheckBox1.Enabled = False
Case (8)
CheckBox1.Enabled = False
Case (9)
CheckBox1.Enabled = False
Case (10)
CheckBox1.Enabled = False
Case (12)
CheckBox1.Enabled = False
Case (14)
CheckBox1.Enabled = False
Case (17)
CheckBox1.Enabled = False
Case (21)
CheckBox1.Enabled = False
Case (28)
CheckBox1.Enabled = False
Case (30)
CheckBox1.Enabled = False
Case (33)
CheckBox1.Enabled = False
Case (34)
CheckBox1.Enabled = False
Case (35)
CheckBox1.Enabled = False
Case (36)
CheckBox1.Enabled = False
Case (37)
CheckBox1.Enabled = False
Case (38)
CheckBox1.Enabled = False
Case (40)
CheckBox1.Enabled = False
Case (41)
CheckBox1.Enabled = False
Case (43)
CheckBox1.Enabled = False
Case (45)
CheckBox1.Enabled = False
Case (47)
CheckBox1.Enabled = False
Case (48)
CheckBox1.Enabled = False
End Select
End Sub
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim screenOffset As Integer = offset(ComboBox1.SelectedIndex) * 360 / 1440
e.Graphics.DrawImage(PictureBox1.Image, screenOffset, 0)
End Sub
Public Function clockDrawX(ByVal minuteVal As Integer, ByVal handLen As Integer)
Const PI As Double = 3.14159265
Dim angle As Double
Dim totalIncrements As Integer = 100
angle = (PI * 2 * minuteVal) / totalIncrements - PI / 2
Return CInt(handLen * Math.Cos(angle))
End Function
Public Function clockDrawY(ByVal minuteVal As Integer, ByVal handLen As Integer)
Const PI As Double = 3.14159265
Dim angle As Double
Dim totalIncrements As Integer = 100
angle = (PI * 2 * minuteVal) / totalIncrements - PI / 2
Return CInt(handLen * Math.Sin(angle))
End Function
Public Sub drawhand(ByVal onObj As PictureBox, ByVal minPos As Integer, ByVal handInset As Integer, ByVal over As Integer, ByVal thick As Integer, ByVal clockInset As Integer, ByVal e As Windows.Forms.PaintEventArgs)
Dim centerX As Integer
Dim centerY As Integer
Dim clockRadius As Integer
Dim radius As Integer
Dim x0 As Integer
Dim y0 As Integer
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim x3 As Integer
Dim y3 As Integer
If (onObj.Width < onObj.Height) Then
clockRadius = onObj.Width / 2 - clockInset
Else
clockRadius = onObj.Height / 2 - clockInset
End If
centerX = clockRadius
centerY = clockRadius
radius = clockRadius - handInset
x0 = centerX + clockDrawX(minPos, radius)
y0 = centerY + clockDrawY(minPos, radius)
x1 = centerX + clockDrawX((minPos + 25) Mod 100, thick / 2)
y1 = centerY + clockDrawY((minPos + 25) Mod 100, thick / 2)
x2 = centerX + clockDrawX((minPos + 50) Mod 100, over)
y2 = centerY + clockDrawY((minPos + 50) Mod 100, over)
x3 = centerX + clockDrawX((minPos + 75) Mod 100, thick / 2)
y3 = centerY + clockDrawY((minPos + 75) Mod 100, thick / 2)
' do the actual drawing
Dim handPen As New Pen(Color.Black)
Dim handCoord(3) As Point
handCoord(0).X = x0
handCoord(0).Y = y0
handCoord(1).X = x1
handCoord(1).Y = y1
handCoord(2).X = x2
handCoord(2).Y = y2
handCoord(3).X = x3
handCoord(3).Y = y3
Dim handBrush As New SolidBrush(Color.SeaGreen)
e.Graphics.FillPolygon(handBrush, handCoord)
e.Graphics.DrawLine(handPen, x0, y0, x1, y1)
e.Graphics.DrawLine(handPen, x1, y1, x2, y2)
e.Graphics.DrawLine(handPen, x2, y2, x3, y3)
e.Graphics.DrawLine(handPen, x3, y3, x0, y0)
End Sub
Private Sub PictureBox2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
Dim brush As New SolidBrush(System.Drawing.Color.Blue)
Dim brush1 As New SolidBrush(System.Drawing.Color.Brown)
Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim currentTime As Integer = Now().Hour
Dim currentTime1 As Integer = Now().Minute
Dim h As Integer = PictureBox2.Width / 2 - 20
For i = 1 To 60
x = h + h * System.Math.Sin((6 + 6 * (i - 1)) * PI / 180)
y = h - h * System.Math.Cos((6 + 6 * (i - 1)) * PI / 180)
If (i Mod 5 = 0) Then
e.Graphics.FillEllipse(brush, x, y, 4, 4)
Else
e.Graphics.FillEllipse(brush1, x, y, 2, 2)
End If
Next
Const clockInset As Integer = 2
Const secHandInset As Integer = 16
Const secHandOverHang As Integer = 7
Const secHandWidth As Integer = 7
Const clockInset1 As Integer = 2
Const secHandInset1 As Integer = 35
Const secHandOverHang1 As Integer = 7
Const secHandWidth1 As Integer = 7
drawhand(PictureBox2, CInt(hour), secHandInset, secHandOverHang, secHandWidth, clockInset, e)
drawhand(PictureBox2, CInt(min), secHandInset1, secHandOverHang1, secHandWidth1, clockInset1, e)
drawhand(PictureBox2, CInt(sec), 18, 0, 0, 2, e)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblTimeZone.Text = "Current Time Zone:" + ComboBox1.Text
txtYear.Text = year
nudYear.Value = year
Calendar.Day = day
nudHour.Refresh()
nudMin.Refresh()
nudSec.Refresh()
If (CInt(hour) < 12) Then
rbnAm.Checked = True
Else
rbnPm.Checked = True
End If
nudHour.Value = hour
nudMin.Value = min
nudSec.Value = sec
Select Case (month)
Case (1)
cobMon.Text = "January"
Case (2)
cobMon.Text = "Feberary"
Case (3)
cobMon.Text = "March"
Case (4)
cobMon.Text = "Apirl"
Case (5)
cobMon.Text = "May"
Case (6)
cobMon.Text = "June"
Case (7)
cobMon.Text = "July"
Case (8)
cobMon.Text = "August"
Case (9)
cobMon.Text = "September"
Case (10)
cobMon.Text = "October"
Case (11)
cobMon.Text = " November"
Case (12)
cobMon.Text = "December"
End Select
End Sub
Private Sub nudHour_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudHour.ValueChanged
nudHour.Value = hour
nudMin.Value = min
nudSec.Value = sec
End Sub
Private Sub cobMon_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cobMon.SelectedIndexChanged
Select Case (cobMon.Text)
Case ("January")
Calendar.Month = 1
Case ("Feberary")
Calendar.Month = 2
Case ("March")
Calendar.Month = 3
Case ("Apirl")
Calendar.Month = 4
Case ("May")
Calendar.Month = 5
Case ("June")
Calendar.Month = 6
Case ("July")
Calendar.Month = 7
Case ("August")
Calendar.Month = 8
Case ("September")
Calendar.Month = 9
Case ("October")
Calendar.Month = 10
Case (" November")
Calendar.Month = 11
Case ("December")
Calendar.Month = 12
End Select
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
watchTime += 1
PictureBox2.Refresh()
PictureBox1.Refresh()
End Sub
Private Sub nudYear_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudYear.ValueChanged
txtYear.Text = nudYear.Value
If (nudYear.Value <> 2008) Then
Try
Calendar.Year = Convert.ToString(nudYear.Value)
Catch ex As Exception
End Try
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -