📄 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 + -