前往顾页
以后地位: 主页 > 精通Office > PowerPoint教程 >

例谈制作交互性更强的ppt课件(十四)

时候:2015-01-28 20:05来源:知行网www.zhixing123.cn 编辑:麦田守望者

操纵法度实现变速动画——平抛活动。

  本例中的多数代码必须在放映幻灯片时运行,是以如果是2007或更高版本,需求保存为“启用宏的Powerpoint文稿(*.pptm)”。

 1、输入以下代码。

Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public lTimerID As Long, i As Integer
Public Sub drawOval()
Dim shp As Shape
ActivePresentation.Slides(1).Shapes.AddShape(msoShapeOval, cm2p(1), cm2p(1), cm2p(1), cm2p(1)).Name = "o1"
End Sub
Sub moveOval()
Dim j As Integer
If i = 100 Then
ActivePresentation.Slides(1).Shapes("o1").Left = cm2p(1): ActivePresentation.Slides(1).Shapes("o1").Top = cm2p(1)
i = 0
For j = 0 To 99
ActivePresentation.Slides(1).Shapes("line" & j).Delete
Next
ElseIf i = 0 Then
StartTimer 10
End If
End Sub
Sub StartTimer(lDuration As Long)
If lTimerID = 0 Then
lTimerID = SetTimer(0&, 0&, lDuration, AddressOf OnTime)
Else
Call StopTimer
lTimerID = SetTimer(0&, 0&, lDuration, AddressOf OnTime)
End If
End Sub
Sub StopTimer()
KillTimer 0&, lTimerID
End Sub
Sub OnTime()
Dim x1 As Single, x2 As Single, y1 As Single, y2 As Single
x1 = ActivePresentation.Slides(1).Shapes("o1").Left+cm2p(0.5): y1 = ActivePresentation.Slides(1).Shapes("o1").Top+cm2p(0.5)
ActivePresentation.Slides(1).Shapes("o1").Top = cm2p(1 + i * i / 1000)
ActivePresentation.Slides(1).Shapes("o1").Left = cm2p(1 + i / 10)
x2 = ActivePresentation.Slides(1).Shapes("o1").Left+cm2p(0.5): y2 = ActivePresentation.Slides(1).Shapes("o1").Top+cm2p(0.5)
ActivePresentation.Slides(1).Shapes.AddLine(x1, y1, x2, y2).Name = "line" & i
i = i + 1
If i = 100 Then StopTimer
End Sub



  头两段法度引入定时器的API函数,并定义两个全局变量。第三段法度是绘制一个小球并定名(本段运行一次今后可以删失落)。第四段法度,如果i=0,则启动定时器,i=100则从头初始化法度。第五段法度是启动定时器,详细定时器触发的代码见最后一段法度。第六段法度是停止定时器。第七段——也就是最后一段法度——挪动小球并画出一条轨迹,当i=100时停止法度。cm2p函数见前面。

 

  以上在画图的同时给画图工具定名,如许做的目标是,今后可以便利地经由过程名字操纵所绘制的工具。

 2、先在设想视图下履行前面的第一段法度,并绘制一个矩形作为按钮。

 3、选中刚才绘制的矩形,在“拔出”选项卡里单击“行动”按钮,弹出对话框。单击“运行宏”,然后鄙人拉框里挑选moveOval,便可放映运行。

  本文是在运行时逐段画出轨迹的,也能够在画出小球时同时画出抛物线轨迹(用AddPolyLine体例),并画一与背景色彩不异的矩形挡住轨迹,然后在运行时同时挪动小球和矩形。

------分开线----------------------------
标签(Tag):ppt ppt技能 PowerPoint技能 PowerPoint教程 幻灯片 poweroint poweroint技能 PPT模板
------分开线----------------------------
保举内容
猜你感兴趣