⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 vb设计的有关地图移动、设置
💻 VB
字号:
Imports System.Drawing
Imports System.Math

Public Class form1

    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Month.SelectAll()         '选中数字输入框中的文本
        Month.Focus()
        Timer1.Interval = 1000
        Month.SelectedIndex = Date.Now.Month - 1      '设置月份控件的初始值
        Year.Value = Date.Now.Year              '设置年份控件的初始值
    End Sub


    '关于time zone区域的实现代码


    '把时间存入time这个数组中
    Dim time As Integer() = New 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}

    Dim auto As Boolean   '用来存选中的那个区域的Auto delight的值

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim hasSavingsTime(50) As Boolean
        Dim i As Integer
        For i = 0 To 49                   '把每个Auto delight的值按顺序存入hasSavingsTime数组中
            hasSavingsTime(i) = True
        Next i
        hasSavingsTime(0) = False ' (GMT -12:00) Eniwetok, Kwajalein 
        hasSavingsTime(1) = False ' (GMT -11:00) Midway Island, Samoa 
        hasSavingsTime(2) = False ' (GMT -10:00) Hawaii 
        hasSavingsTime(5) = False ' (GMT -07:00) Arizona 
        hasSavingsTime(8) = False ' (GMT -06:00) Mexico City, Tegucigalpa 
        hasSavingsTime(9) = False ' (GMT -06:00) Saskatchewan 
        hasSavingsTime(10) = False ' (GMT -05:00) Bogota, Lima 
        hasSavingsTime(12) = False ' (GMT -05:00) Indiana (East) 
        hasSavingsTime(14) = False ' (GMT -04:00) Caracas, La Paz 
        hasSavingsTime(17) = False ' (GMT -03:00) Buenos Aires, Georgetown 
        hasSavingsTime(21) = False ' (GMT +00:00) Monrovia, Casablanca 
        hasSavingsTime(28) = False ' (GMT +02:00) Harare, Pretoria 
        hasSavingsTime(30) = False ' (GMT +03:00) Baghdad, Kuwait, Nairobi, Riyadh 
        hasSavingsTime(33) = False ' (GMT +04:00) Abu Dhabi, Muscat, Tbilisi 
        hasSavingsTime(34) = False ' (GMT +04:30) Kabul 
        hasSavingsTime(35) = False ' (GMT +05:00) Islamabad, Karachi, Ekaterinburg, Tashkent 
        hasSavingsTime(36) = False ' (GMT +05:30) Bombay, Calcutta, Madras, New Delhi, Colombo 
        hasSavingsTime(37) = False ' (GMT +06:00) Almaty, Dhaka 
        hasSavingsTime(38) = False ' (GMT +07:00) Bangkok, Jakarta, Hanoi 
        hasSavingsTime(40) = False ' (GMT +08:00) Hong Kong, Perth, Singapore, Taipei 
        hasSavingsTime(41) = False ' (GMT +09:00) Tokyo, Osaka, Sapporo, Seoul, Yakutsk 
        hasSavingsTime(43) = False ' (GMT +09:30) Darwin 
        hasSavingsTime(45) = False ' (GMT +10:00) Guam, Port Moresby, Vladivostok 
        hasSavingsTime(47) = False ' (GMT +11:00) Magadan, Solomon Is., New Caledonia 
        hasSavingsTime(48) = False ' (GMT +12:00) Fiji, Kamchatka, Marshall Is

        CheckBox1.Enabled = hasSavingsTime(ComboBox1.SelectedIndex)        '选中区域的Auto delight 值与CheckBox1的Enabled的值对应

        auto = hasSavingsTime(ComboBox1.SelectedIndex)

        '下面代码用来实现地图的移动

        PictureBox1.Refresh()   '促发DrawImage方法执行一遍
        Label1.Text = "Current Time Zone: " & ComboBox1.SelectedItem

    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        'e.Graphics.DrawImage(PictureBox1.Image, CSng(PictureBox1.Location.X - (360 / 1440) * (720 + CInt(time(ComboBox1.SelectedIndex)))), CSng(PictureBox1.Location.Y))

        e.Graphics.DrawImage(PictureBox1.Image, CSng(-(360 / 1440) * (720 + time(ComboBox1.SelectedIndex))), 0)

    End Sub


    '关于data区域的实现代码

    Private Sub Month_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Month.SelectedIndexChanged
        Try
            Select Case Month.SelectedItem
                Case "January"
                    AxCalendar1.Month = 1
                Case "February"
                    AxCalendar1.Month = 2
                Case "March"
                    AxCalendar1.Month = 3
                Case "April"
                    AxCalendar1.Month = 4
                Case "May"
                    AxCalendar1.Month = 5
                Case "June"
                    AxCalendar1.Month = 6
                Case "July"
                    AxCalendar1.Month = 7
                Case "August"
                    AxCalendar1.Month = 8
                Case "September"
                    AxCalendar1.Month = 9
                Case "October"
                    AxCalendar1.Month = 10
                Case "November"
                    AxCalendar1.Month = 11
                Case "December"
                    AxCalendar1.Month = 12
            End Select
        Catch ex As Exception
            Console.WriteLine("catch")
        End Try
    End Sub

    Private Sub Year_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Year.ValueChanged
        Try
            AxCalendar1.Year = Year.Value
        Catch ex As Exception
            Console.WriteLine("catch")
        End Try
    End Sub

    '关于time区域的实现代码

    '计算一指定时刻的位置所对应的 X 坐标的值
    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 * Cos(angle))
    End Function

    '计算一指定时刻的位置所对应的 Y 坐标的值
    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 * Sin(angle))
    End Function

    '依坐标画出一个点
    Public Sub drawDot(ByVal onObj As PictureBox, ByVal e As Windows.Forms.PaintEventArgs, ByVal brush As SolidBrush, ByVal minute As Integer, ByVal clockInset As Integer)
        'Dim clockInset As Integer = 2          ' distance from clock edge to box edge 
        Const dotRadius As Integer = 4           ' 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

        ' 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

        ' 计算点的坐标 
        x = centerX + clockDrawX(minute, clockRadius - dotRadius)
        y = centerY + clockDrawY(minute, clockRadius - dotRadius)

        ' 在坐标位置依据要求画出所需的点 
        e.Graphics.FillEllipse(brush, x, y, dotRadius, dotRadius)

    End Sub

    '画出时钟周围的点
    Private Sub drawWatchFace(ByVal pb As PictureBox, ByVal clockInset As Integer, ByVal e As System.Windows.Forms.PaintEventArgs)
        For i As Integer = 1 To 60
            If i Mod 5 = 0 Then                     '当是5、10、15、20....等数时点为黑色
                Dim brush1 As New SolidBrush(Color.Black)  'brush
                drawDot(PictureBox2, e, brush1, i, clockInset)
            Else                                '其它的点为浅灰色
                Dim brush2 As New SolidBrush(Color.LightGray)  'brush
                drawDot(PictureBox2, e, brush2, i, clockInset)
            End If
        Next
    End Sub

    '画出一个指针
    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 + (onObj.Width - onObj.Height) / 2 + 2 * clockInset
        centerY = clockRadius + 2 * clockInset
        radius = clockRadius - handInset
        x0 = centerX + clockDrawX(minPos, radius)
        y0 = centerY + clockDrawY(minPos, radius)
        x1 = centerX + clockDrawX((minPos + 15) Mod 60, thick / 2)
        y1 = centerY + clockDrawY((minPos + 15) Mod 60, thick / 2)
        x2 = centerX + clockDrawX((minPos + 30) Mod 60, over)
        y2 = centerY + clockDrawY((minPos + 30) Mod 60, over)
        x3 = centerX + clockDrawX((minPos + 45) Mod 60, thick / 2)
        y3 = centerY + clockDrawY((minPos + 45) Mod 60, 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 drawWatch(ByVal onObj As PictureBox, ByVal currentTime As Integer, ByVal e As System.Windows.Forms.PaintEventArgs)

        Const clockInset As Integer = 2
        drawWatchFace(onObj, clockInset, e)

        '画时针
        Const hourHandInset As Integer = 30
        Const hourHandOverHang As Integer = 8
        Const hourHandWidth As Integer = 8
        ' Subtraction of 50 is necessary because currentPos/100 gets rounded up.  This causes     
        'the second hand to move at 50 microseconds rather than at 100.     
        'drawhand(onObj, (currentTime - 30) / 60, hourHandInset, hourHandOverHang, hourHandWidth, clockInset, e)
        drawhand(onObj, (currentTime - 360) / (60 * 12), hourHandInset, hourHandOverHang, hourHandWidth, clockInset, e)

        '画分针
        Const secHandInset As Integer = 15
        Const secHandOverHang As Integer = 7
        Const secHandWidth As Integer = 7
        ' Subtraction of 30 is necessary because currentPos/60 gets rounded up.  This causes     
        'the second hand to move at 30 microseconds rather than at 60.     
        'drawhand(onObj, (currentTime) / 60, secHandInset, secHandOverHang, secHandWidth, clockInset, e)
        drawhand(onObj, (currentTime - 30) / 60, secHandInset, secHandOverHang, secHandWidth, clockInset, e)

        '画秒针
        Const msecondHandInset As Integer = 10
        ' Amount that msecond hand goes past center point      
        Const msecondHandOverHang As Integer = 0
        ' Width of the msecond hand      
        Const msecondHandWidth As Integer = 0
        ' Draw msecond hand       
        drawhand(onObj, currentTime, msecondHandInset, msecondHandOverHang, msecondHandWidth, clockInset, e)

    End Sub

    Dim watchTime As Integer = Date.Now.Hour * 3600 + Date.Now.Minute * 60 + Date.Now.Second

    Private Sub PictureBox2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint

        drawWatch(PictureBox2, watchTime, e)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        watchTime += 1

        PictureBox2.Refresh()

        If Date.Now.Hour < 12 Then
            NumericUpDown1.Value = Date.Now.Hour
            RadioButton1.Select()
        ElseIf Date.Now.Hour = 12 Then
            NumericUpDown1.Value = 12
            RadioButton2.Select()
        Else
            NumericUpDown1.Value = Date.Now.Hour - 12
            RadioButton2.Select()
        End If
        NumericUpDown2.Value = Date.Now.Minute
        NumericUpDown3.Value = Date.Now.Second

    End Sub

    '显示一些属性的值
    Private Sub Description(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim msg As String
        Dim title As String
        Dim style As MsgBoxStyle
        Dim response As MsgBoxResult

        msg = "Applied ... " & Chr(13) & "=============================================" & _
        Chr(13) & "Year = " & AxCalendar1.Year & Chr(13) & "Month = " & AxCalendar1.Month & Chr(13) & _
        "Day = " & AxCalendar1.Day & Chr(13) & "Hour = " & Date.Now.Hour & Chr(13) & "Minute = " & Date.Now.Minute & Chr(13) & _
        "Second = " & Date.Now.Second & Chr(13) & "Time zone = " & ComboBox1.SelectedItem & Chr(13) & _
        "Offset from GMT =" & time(ComboBox1.SelectedIndex) & _
        " minutes" & Chr(13) & "Auto daylight = " & auto & Chr(13) & _
        "============================================="
        style = MsgBoxStyle.DefaultButton1
        title = "Date and Time"
        response = MsgBox(msg, style, title)
        If response = MsgBoxResult.Yes Then
            Me.Close()
        End If
    End Sub

    '显示一些属性值并同时关闭程序窗口
    Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click
        Description(sender, e)
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Description(sender, e)
        Me.Close()
    End Sub

    '同上 ,但不关闭程序窗口

    Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
        Description(sender, e)
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -