?? vb19.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0057)http://www.pconline.com.cn/experience/subject/VB/vb19.htm -->
<HTML><HEAD><TITLE>|><| 太平洋電腦信息網</TITLE><!-- #BeginTemplate "/Templates/0723.dwt" --><!-- #BeginEditable "doctitle" --><!-- #EndEditable -->
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK
href="vb19.files/text.css" rel=stylesheet>
<STYLE type=text/css>.sfont {
LINE-HEIGHT: 18pt
}
</STYLE>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD vAlign=top width="100%">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR bgColor=#303880>
<TD><A href="http://www.pconline.com.cn/"><IMG alt=太平洋電腦信息網 border=0
height=18 hspace=30 src="vb19.files/txtpconline.gif"
width=96></A><IMG height=10 src="vb19.files/blank.gif"
width=400></TD></TR></TBODY></TABLE></TD>
<TD align=right background=vb19.files/bw.gif noWrap width=130><IMG
height=26 src="vb19.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/sitemap/"><IMG alt=網站地圖 border=0
height=26 src="vb19.files/sitemap.gif" width=21></A><IMG height=26
src="vb19.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/tpy/"><IMG alt=關于太平洋 border=0 height=26
src="vb19.files/aboutus.gif" width=21></A><IMG height=26
src="vb19.files/bw.gif" width=10><A
href="http://www.pconline.com.cn/tpy/tariff.html"><IMG alt=與我們聯系 border=0
height=26 src="vb19.files/contact.gif" width=21></A><IMG height=26
src="vb19.files/bw.gif" width=10></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD bgColor=#666666><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD> </TD>
<TD colSpan=2 noWrap><A
href="http://www.pconline.com.cn/experience/index.html"><IMG
align=absBottom alt=企業之窗 border=0 height=15
src="vb19.files/txtexperience.gif" width=68></A> <A
href="http://www.pconline.com.cn/">首 頁</A> <A
href="http://www.pconline.com.cn/market/">今日報價</A> <A
href="http://www.pconline.com.cn/recommend/">產品推介</A> <A
href="http://www.pconline.com.cn/yp/">企業之窗</A> <A
href="http://www.pconline.com.cn/news/">科技新聞</A> <A
href="http://www.pconline.com.cn/product/">產品查詢</A> <A
href="http://www.pconline.com.cn/download/">軟件下載</A></TD></TR>
<TR>
<TD><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD><IMG height=1 src="vb19.files/blank.gif" width=21></TD>
<TD bgColor=#ffa000 colSpan=2><IMG height=1 src="vb19.files/blank.gif"
width=1></TD></TR>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD bgColor=#cdcdcd><IMG height=5 src="vb19.files/blank.gif" width=1></TD>
<TD align=right colSpan=3><IMG height=6 src="vb19.files/ffa000.gif"
width=1></TD></TR>
<TR>
<TD bgColor=#666666><IMG height=1 src="vb19.files/blank.gif" width=1></TD>
<TD align=right><A href="http://www.pconline.com.cn/"><IMG alt=太平洋電腦信息網
border=0 height=35 src="vb19.files/pconline.com.cn.gif" vspace=10
width=162></A></TD>
<TD> </TD>
<TD vAlign=bottom><!-- #BeginEditable "important_news" --><IMG height=40
src="vb19.files/blank.gif" width=350><!-- #EndEditable --></TD>
<TD align=right vAlign=top><!-- #BeginEditable "adv_top" --><IMG alt=廣告位
height=43 src="vb19.files/icon.gif"
width=190><!-- #EndEditable --></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666 width=1><IMG height=1 src="vb19.files/blank.gif"
width=1></TD>
<TD vAlign=top width=170><!-- #BeginEditable "addons" --><!--替代為附加信息 --><!-- #EndEditable --></TD>
<TD bgColor=#666666 width=1><IMG height=1 src="vb19.files/blank.gif"
width=1></TD>
<TD><IMG height=1 src="vb19.files/blank.gif" width=21></TD>
<TD colSpan=3 vAlign=top width=566><!-- #BeginEditable "1" -->
<DIV align=left>
<P><IMG height=1 src="vb19.files/blank.gif" width=566><BR><IMG height=1
src="vb19.files/666666.gif" width=420><BR><IMG height=13
src="vb19.files/blank.gif" width=1><A
href="http://www.pconline.com.cn/experience/">經驗共享</A> ><SPAN
class=greenb><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">專題教程</A></SPAN><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">
VB專區</A>> <BR><IMG height=1 src="vb19.files/666666.gif" vspace=1
width=420><BR></P>
<P align=center><STRONG><SPAN class=f style="FONT-SIZE: 14px"><FONT
color=#000066><SPAN class=sfont>VB設計動畫時鐘</SPAN></FONT></SPAN></STRONG>
</P></DIV>
<P align=justify><SPAN class=sfont><FONT color=#000000><SPAN class=f>程 序
名:Sec-Time.vbp</SPAN></FONT><SPAN class=f><BR>程序類別:完整的VB程序<BR>功
能:顯示一個動畫時鐘,該時針隨著每一秒而動態變化。</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><FONT color=#000000><SPAN
class=f>程序說明</SPAN></FONT></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f> 1.如何畫時鐘表盤上的所有直線元素?<BR> 用Load命令建立原始Line控制的14個拷貝(因為表盤有12個點和時、分、秒共15個Line),該控制數組每一個實例的端點坐標屬性設置為每條線在時鐘表盤上的適當位置。這些拷貝中大多數只放置一次,而3個Line控制每秒鐘更新一次,產生時鐘指針移動的感覺。<BR> 注意:在應用程序代碼中并沒有直接擦除任何一條線。當我們改變每一個Line控制的端點時,每一根針在移動時擦除和重畫的所有技術工作都由VB來處理。</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f> 2.如何修改時針的形狀?<BR> 通過調整代碼中的屬性設置,可以改變時鐘的形狀。例如:通過改變每一個Line控制的Borderwidth屬性設置,可以建立更細或更粗的線。</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f> 3.計時器的Interval(間距)屬性設置<BR> 計時器的Interval屬性設置為100,即為1/10秒。</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f>程序的編寫與執行</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f> (1)新建工程<BR> 先新建一個工程(工程類型為標準EXE),然后用“工具箱”中的工具加入一個Timer1(計時器)和line1(直線),其index(指針)分別設置為空和0。然后雙擊Form1窗體,輸入源代碼。</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN class=f> (2)程序源代碼<BR> Option
Explicit<BR> DefDbl A-Z<BR> Private Sub Form_Load()<BR> timer1.Interval
= 100<BR> Width = 4000<BR> Height = 4000<BR> Left = Screen.Width \ 2 -
2000<BR> Top = (Screen.Height - Height) \ 2<BR> End Sub<BR> Private Sub
Form_Resize()<BR> Dim i, Angle<BR> Static flag As Boolean<BR> If flag =
False Then<BR> flag = True<BR> For i = 0 To
14<BR> ’畫出表盤12個點和時、分、秒共15個LINE<BR> If i > 0 Then Load
Line1(i)<BR> Line1(i).Visible = True<BR> Line1(i).BorderWidth =
5<BR> Line1(i).BorderColor = RGB(0, 128, 0) ’設置LINE的粗細和顏色<BR> Next
i<BR> End If<BR> For i = 0 To 14<BR> Scale (-1, 1)-(1,
-1)<BR> Angle = i * 2 * Atn(1) / 3<BR> Line1(i).X1 = 0.9 *
Cos(Angle)<BR> Line1(i).Y1 = 0.9 * Sin(Angle)<BR> Line1(i).X2 =
Cos(Angle)<BR> Line1(i).Y2 = Sin(Angle)<BR> Next i<BR> End
Sub<BR> Private Sub timer1_Timer()<BR> Const HH = 0<BR> Const MH =
13<BR> Const SH = 14<BR> Dim Angle<BR> Static LS<BR> If Second(Now) =
LS Then Exit Sub<BR> LS = Second(Now)<BR> Angle = 0.5236 * (15 -
(Hour(Now) + Minute(Now) / 60))’設置時針<BR> Line1(HH).X1 =
0<BR> Line1(HH).Y1 = 0<BR> Line1(HH).X2 = 0.3 *
Cos(Angle)<BR> Line1(HH).Y2 = 0.3 * Sin(Angle)<BR> Angle = 0.1047 * (75
- (Minute(Now) + Second(Now) / 60))’設置分針<BR> Line1(MH).X1 =
0<BR> Line1(MH).Y1 = 0<BR> Line1(MH).X2 = 0.7 *
Cos(Angle)<BR> Line1(MH).Y2 = 0.7 * Sin(Angle)<BR> Angle = 0.5236 * (75
- Second(Now))<BR> ’設置秒針<BR> Line1(SH).X1 = 0<BR> Line1(SH).Y1 =
0<BR> Line1(SH).X2 = 0.8 * Cos(Angle)<BR> Line1(SH).Y2 = 0.8 *
Sin(Angle)<BR> form1.Caption = Str(Now())<BR> '窗口顯示精確的日期和數字化的時間<BR> End
Sub</SPAN></SPAN></P>
<P align=justify><SPAN class=sfont><SPAN
class=f> (3)程序的編譯和執行<BR> 點擊VB“運行”菜單中的“啟動”或“全面編譯”命令,即可對程序編譯并運行!<BR> 注:上述程序在中文Windows
98和 VB5.0中文企業版下調試通過。</SPAN></SPAN>
<P align=right><A
href="http://www.pconline.com.cn/experience/subject/VB/index.html">----更多的文章</A></P>
<P align=right> <!-- #EndEditable --></P></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=760>
<TBODY>
<TR>
<TD bgColor=#666666 width=1><IMG height=1 src="vb19.files/blank.gif"
width=1></TD>
<TD align=right vAlign=bottom width=170><IMG height=10
src="vb19.files/blank.gif" width=170><BR></TD>
<TD bgColor=#666666 width=1><IMG height=1 src="vb19.files/blank.gif"
width=1></TD>
<TD width=21><IMG height=1 src="vb19.files/blank.gif" width=21></TD>
<TD bgColor=#eeeeee width=566><IMG height=10 src="vb19.files/blank.gif"
width=566><BR>版權所有©1999 太平洋電腦信息網<BR><FONT
face="Arial, Helvetica, sans-serif"><A
href="mailto:exp@pconline.com.cn">exp@pconline.com.cn</A></FONT> <IMG
height=1 src="vb19.files/hhvisit.html" width=1> </TD></TR></TBODY></TABLE><!-- #EndTemplate --></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -