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

📄 form1.frm

📁 此程序更祥细介绍和运用VB的绘图功能设计的指针时钟。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8745
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   12840
   LinkTopic       =   "Form1"
   ScaleHeight     =   8745
   ScaleWidth      =   12840
   StartUpPosition =   3  '窗口缺省
   Begin VB.PictureBox Picture1 
      BackColor       =   &H0080FF80&
      Height          =   8175
      Left            =   0
      ScaleHeight     =   8115
      ScaleWidth      =   12795
      TabIndex        =   0
      Top             =   0
      Width           =   12855
      Begin VB.Timer Timer1 
         Interval        =   1000
         Left            =   0
         Top             =   0
      End
      Begin VB.PictureBox Picture2 
         AutoSize        =   -1  'True
         Height          =   6810
         Left            =   1680
         Picture         =   "Form1.frx":0000
         ScaleHeight     =   6750
         ScaleWidth      =   9000
         TabIndex        =   1
         Top             =   720
         Width           =   9060
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            BackColor       =   &H8000000D&
            BackStyle       =   0  'Transparent
            Caption         =   "Label1"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H0000FF00&
            Height          =   210
            Index           =   1
            Left            =   4200
            TabIndex        =   3
            Top             =   4560
            Width           =   720
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            BackColor       =   &H8000000D&
            BackStyle       =   0  'Transparent
            Caption         =   "Label1"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H0080FF80&
            Height          =   210
            Index           =   0
            Left            =   4200
            TabIndex        =   2
            Top             =   4200
            Width           =   720
         End
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'定义保存当前时间小时,分钟和秒
Dim CurrentHour As Single, CurrentMinite As Single, CurrentSecond As Single
'定义画指针时的起点坐标和终点坐标
Dim HandStartX As Integer, HandStartY As Integer, HandEndX As Integer, HandEndY As Integer  'HandEndX  HandEndy终点坐标、这里即圆心坐标
'下面变量用来保存三个指针的长度
Dim SecondLen As Integer, SecondLenH As Integer, MiniteLen As Integer, HourLen As Integer



'由于指针的终点是固定的,根据圆的参数方程和坐标平移公式,计算出指针起点坐标。
Private Sub ScaleStartXY(CurrentTime As Single, HandLen As Integer)
HandStartX = HandLen * Sin(Scaleangel(CurrentTime)) + HandEndX
HandStartY = HandLen * Cos(Scaleangel(CurrentTime)) + HandEndY
End Sub
'将角度转换成弧度的函数代码,由于VB只能用于弧度。指针实际偏转角度=180-当前时间*6;指针的实际弧度=指针角度*3.1415926/180
Private Function Scaleangel(CurrentTime As Single) As Single
Scaleangel = (180 - CurrentTime * 6) * 3.1415926 / 180
End Function
Private Sub Form_Load()


On Error Resume Next  '避免错误
    ScaleMode = 1   '坐标度量单位是缇
' 窗口表的图像控件===================
'Image1.ScaleMode = 1

 '以下四行使窗体为全屏幕
Form1.Left = 0                      '以下四行使窗体为全屏幕
Form1.Top = 0                       '窗体位置
Form1.Width = Screen.Width    'Screen.Width等于有效宽度
Form1.Height = Screen.Height  ' Screen.Height  等于有效宽度
   
Picture1.Width = Form1.Width
Picture1.Height = Form1.Height
Picture1.Left = Form1.Left
Picture1.Top = Form1.Top

Picture2.AutoSize = True
Picture2.Left = (Picture1.Width - Picture2.Width) / 2
Picture2.Top = (Picture1.Height - Picture2.Height) / 2

Label1(0).Left = (Picture2.Width - Label1(0).Width) / 2

Label1(1).Left = (Picture2.Width - Label1(1).Width) / 2


'确定圆心坐标,后面的加20和减53,是因为图片在制作时候,圆心坐标不太准确做的一点调试
HandEndX = Picture2.Width / 2 - 40
HandEndY = Picture2.Height / 2 - 40

'确定三个指针的长度
SecondLen = 1550
SecondLenH = 500 '秒针尾部
MiniteLen = 1250
HourLen = 850
End Sub
Private Sub Form_Unload(Cancel As Integer)

Unload Me
End Sub

'根据当前时间画出秒针、分针和时针
Private Sub Timer1_Timer()   '定时器时间函数,每一秒钟触发一次。
Timer1.Interval = 1000  '必须设置否则不显示时间和日期

Label1(0).Caption = Str(Date)  '将当前日期用数字显示出来,若“Time()”则显示时间
Label1(1).Caption = GetWeek(Date)  '显示系统星期


Picture2.Refresh       '刷新Form1(清除上一秒钟所画的三个指针)

CurrentSecond = Second(Time())   '取当前时间的“秒”
CurrentMinite = Minute(Time())   '取当前时间的“分”
CurrentHour = ((Hour(Time()) Mod 12) + CurrentMinite / 60) * 5   '取当前时间的“小时”
'Label8.Caption = Str(Date)  '将当前日期用数字显示出来,若“Time()”则显示时间
'Label9.Caption = GetWeek(Date)  '显示系统星期

Call ScaleStartXY(CurrentHour, HourLen)     '根据当前“小时”计算小时坐标
Picture2.DrawWidth = 6  '时针宽为5 个像素   DrawWidth指线宽度
Picture2.Line (HandStartX, HandStartY)-(HandEndX, HandEndY)  '画出时针


Call ScaleStartXY(CurrentMinite, MiniteLen) '根据当前“分”计算的坐标
Picture2.DrawWidth = 3.5  '分针的宽为3个像素
Picture2.Line (HandStartX, HandStartY)-(HandEndX, HandEndY)  '画出分针


Picture2.DrawWidth = 1.5  '线宽为1个像素,秒针
Call ScaleStartXY(CurrentSecond, SecondLen)  '根据当前“秒”计算的坐标
Picture2.Line (HandStartX, HandStartY)-(HandEndX, HandEndY), QBColor(12)  '画出秒针,QBColor(12)线条颜色,12指亮红色

Picture2.DrawWidth = 3.5  '线宽为1个像素,秒针尾部
Call ScaleStartXY(CurrentSecond - 30, SecondLenH) '根据当前“秒”计算的坐标
Picture2.Line (HandStartX, HandStartY)-(HandEndX, HandEndY), QBColor(12)  '画出秒针,QBColor(12)线条颜色,12指亮红色

Picture2.DrawWidth = 5.5   '线宽为5.5个像素,起到填充圆的目的
Picture2.Circle (HandEndX, HandEndY), 40, QBColor(12)      '画圆,SAng、EAng和Mod省略为直接画圆,40为半径
'Form1.FillColor = 12

 '#注意:要先画时针再画分针,量后画秒针,因为秒针在量上面,最底面是时针,先画的在最底部
Beep

End Sub

⌨️ 快捷键说明

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