計(jì)算機(jī)二級VB輔導(dǎo):VB繪制走動(dòng)的表針

字號(hào):

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Me.Text = Date.Now.ToString
    Dim FmGraphics As System.Drawing.Graphics
    FmGraphics = Me.CreateGraphics
    Dim TmLong As Double = 75
    Dim HourPoint(1), MinutePoint(1), SecondPoint(1), OriginPoint As System.Drawing.PointF
    OriginPoint.X = 75
    OriginPoint.Y = 75
    Me.Refresh()
    Dim angle As Double
    angle = -0.5263 * (15 - (Hour(Now) +加入收藏 Minute(Now) / 60))
    HourPoint(0).X = OriginPoint.X
    HourPoint(0).Y = OriginPoint.Y
    HourPoint(1).X = OriginPoint.X + 0.3 * TmLong * Cos(angle)
    HourPoint(1).Y = OriginPoint.Y + 0.3 * TmLong * Sin(angle)
    Dim FmPen As System.Drawing.Pen
    FmPen = New System.Drawing.Pen(System.Drawing.Color.Gold, 3)
    FmGraphics.DrawLine(FmPen, HourPoint(0), HourPoint(1))
    angle = -0.1047 * (75 - (Minute(Now) + Second(Now) / 60))
    MinutePoint(0).X = OriginPoint.X
    MinutePoint(0).Y = OriginPoint.Y
    MinutePoint(1).X = OriginPoint.X + 0.5 * TmLong * Cos(angle)
    MinutePoint(1).Y = 75 + 0.5 * TmLong * Sin(angle)
    FmPen = New System.Drawing.Pen(System.Drawing.Color.Red, 3)
    FmGraphics.DrawLine(FmPen, MinutePoint(0), MinutePoint(1))
    angle = -0.5263 * (75 - Second(Now))
    SecondPoint(0).X = OriginPoint.X
    SecondPoint(0).Y = OriginPoint.Y
    SecondPoint(1).X = OriginPoint.X + 0.7 * TmLong * Cos(angle / 5)
    SecondPoint(1).Y = OriginPoint.Y + 0.7 * TmLong * Sin(angle / 5)
    FmPen = New System.Drawing.Pen(System.Drawing.Color.White, 2)
    FmGraphics.DrawLine(FmPen, SecondPoint(0), SecondPoint(1))
    FmGraphics.Dispose()
    End Sub