|
|
|
|
|
Dicas
|
|
Visual Basic (Forms/MDI)
|
|
|
Título da Dica: Desenhar um relógio analógico usando somente código.
|
|
|
|
Postada em 16/3/2004 por PC
'Desenhe 1 (UM) TIMER em seu formulário e cole o codigo abaixo.
Private Sub Run(O As Object) Const PI As Single = 3.1415 Dim NewTime As Single Dim GocH As Single, GocM As Single, GocS As Single Dim H As Single, M As Single, S As Single Dim r As Single NewTime = Time H = Hour(NewTime) M = Minute(NewTime) S = Second(NewTime) GocH = PI * ((H Mod 12) / 6 + M / 360 + S / 4320) GocM = PI * (M / 30 + S / 1800) GocS = PI * ((Timer + 1.7) / 30) O.Cls If (O.ScaleHeight < O.ScaleWidth) Then r = O.ScaleHeight / 2 Else r = O.ScaleWidth / 2 VeKim O, 3.5 * r / 5, GocH, vbBlue, 6 'hora VeKim O, 5 * r / 6, GocM, vbDesktop, 3 'minuto VeKim O, r, GocS, vbRed, 1 'segundo VeKim O, r / 6, PI + GocS, vbRed, 2 Me.Caption = Time End Sub
Private Sub VeKim(O As Object, r As Single, Goc As Single, Mau As Long, Size As Single) Dim Xo As Single, Yo As Single, X As Single, Y As Single Xo = O.ScaleWidth / 2 Yo = O.ScaleHeight / 2 X = Xo + r * Sin(Goc) Y = Yo - r * Cos(Goc) O.ForeColor = Mau O.DrawWidth = Size O.Line (Xo, Yo)-(X, Y) End Sub
Private Sub Form_Resize() Timer1.Interval = 50 Run Me End Sub
Private Sub Timer1_Timer() Run Me End Sub
|
|
|
|
|