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

📄 vb10.htm

📁 从太平洋上下载下来的打包学习VB的教程。 》VB专区 ·Visual Basic 的数据库编程 ·使用VB建立Web Server   ·VB与Windows资源管理器互拷文件
💻 HTM
📖 第 1 页 / 共 2 页
字号:
</SPAN></PRE>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 
      <B>三、使用PictureClip控件实现动画</B> </SPAN>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 
      该控件提供了存储多个图像信息的技术,其访问方式不是向AniPushButton依次切换每幅图像,而是先将多幅图像依次有序存放在一个.bmp文件中,.bmp中的图像将被均匀分割成许多小块,每一块作为动画切换的一幅图。 
      </SPAN>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 下面的程序将实现一个转动陀螺的动画效果。 
      </SPAN>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 在程序的声明段定义变量: </SPAN><PRE><SPAN class=sfont>

Dim y As Integer

Dim toggle As Integer



Private Sub Form_Load()

  picture1.Picture = PictureClip1.

   GraphicCell(0)  使用第一幅为开始帧

    y = 0

    toggle=0

End Sub



Private Sub cmd_onoff_Click()  开关命令按钮

    If toggle = 0 Then

        cmd_onoff.Caption = "停止"

        toggle = 1

    Else

        cmd_onoff.Caption = "旋转"

        toggle = 0

    End If

End Sub

Private Sub Timer1_Timer()

If toggle = 1 Then spin   满足条件,调图切换子程序

End Sub

Private Sub spin()

        y = y + 1: If y = 17 Then y = 0

        picture1.Picture = PictureClip1.

        GraphicCell(y)  图切换一帧

End Sub

</SPAN></PRE>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 
      在上面的程序中,使用了命令按钮、图片控件、定时器和图像剪切控件等功能,其中最主要的是制作图像文件。图像文件制作分两个过程,首先制作单个的图像文件,然后,将这些图像文件合并成一个图像文件,存于一个.bmp文件中,在图像合成时可使用WINDOWS/95中的“画图”,用粘贴的方法完成。注意,在图像合成时,应设置状态栏参数以确定图像的精确位置,否则,在动画过程中,图像会出现跳动和不稳定感。 
      </SPAN>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 
      <B>四、使用Image实现动画效果</B> </SPAN>
      <P><SPAN class=sfont><FONT color=#ffffff>----</FONT> 
      该功能用定时器控件来控制移动和地球转动的速度,当然,其速度还与程序中设定的步长有关系,具体程序片段如下: </SPAN>
      <DIV align=right>
      <DIV align=left>
      <DIV align=right>
      <DIV align=left><PRE><SPAN class=sfont>

Private Sub Form_Load()

Timer_animate.inteval=100   INTEVAL属性为100ms

Timer_animate.enabled=true  启动动画定时器

End Sub

Private Sub Timer_animate_Timer()

Call ani_Image   定时调移动子程序

End Sub

Sub IncrFrame()

 FrameNum = FrameNum + 1  帧加1

 If FrameNum &gt; 5 Then  

 最后一帧图像显示之后返回第一帧

 FrameNum = 1

    End If

 Imageearth(0).Picture = Imageearth(FrameNum).Picture 

 将该帧图像赋给运动的Imageearth(0)控件的Picture属性

    End Sub

Sub ani_Image()   控制移动子程序

    Select Case Motion  控制移动方向的变量

    Case 1   向上和向左移动,步长50 twips

        Imageearth(0).Move Imageearth(0).

         Left - 50, Imageearth(0).Top - 50

          IncrFrame  切换到下一幅图

         If Imageearth(0).Left &lt; = 0 Then   向左移动到了边界

            Motion = 2  向上和向右移动

         ElseIf Imageearth(0).Top &lt; = 0 Then

            Motion = 4  向上移动到了边界,改向下和向左移动

        End If

    Case 2    向右和向上

        Imageearth(0).Move Imageearth(0).Left + 50,

         Imageearth(0).Top - 50

              IncrFrame

        到了右边界,转为向左和向上

        If Imageearth(0).Left &gt;= (startform.Width

         - Imageearth(0).Width) Then

            Motion = 1

        ElseIf Imageearth(0).Top &lt; = 0 Then

            Motion = 3   向右向下

        End If

    Case 3     向右向下

      Imageearth(0).Move Imageearth(0).Left + 50,

      Imageearth(0).Top + 50

          IncrFrame

       If Imageearth(0).Left &gt;= (startform.Width 

        - Imageearth(0).Width) Then

            Motion = 4   向左向下

       ElseIf Imageearth(0).Top &gt;= 

       (startform.Height - Imageearth(0).Height) - 680 Then

            Motion = 2   向右向上,其中680 twips是标题和菜单的高度

        End If

    Case 4   向左向下

      Imageearth(0).Move Imageearth(0).Left - 50,

      Imageearth(0).Top + 50

       IncrFrame

     If Imageearth(0).Left &lt; = 0 Then   

     是否到了左边界,如到了转向右向下

            Motion = 3

         是否到了下边界

        ElseIf Imageearth(0).Top &gt;= (startform.Height 

       - Imageearth(0).Height) - 680 Then

            Motion = 1  向左向上

        End If

    End Select

End Sub

</SPAN></PRE>
      <P align=right><A 
      href="http://www.pconline.com.cn/experience/subject/VB/index.html">----更多的文章</A></P></DIV></DIV></DIV></DIV><!-- #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="vb10.files/blank.gif" 
      width=1></TD>
    <TD align=right vAlign=bottom width=170><IMG height=10 
      src="vb10.files/blank.gif" width=170><BR></TD>
    <TD bgColor=#666666 width=1><IMG height=1 src="vb10.files/blank.gif" 
      width=1></TD>
    <TD width=21><IMG height=1 src="vb10.files/blank.gif" width=21></TD>
    <TD bgColor=#eeeeee width=566><IMG height=10 src="vb10.files/blank.gif" 
      width=566><BR>版权所有&copy;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="vb10.files/hhvisit.html" width=1> </TD></TR></TBODY></TABLE><!-- #EndTemplate --></BODY></HTML>

⌨️ 快捷键说明

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