|
帮你找的资料,供你参考!
图片或图形的任意拖拽在课件和游戏中经常用到。PPT中要实现图片或图形的任意拖拽需要通过VBA编程。现介绍利用图像控件实现图片任意拖拽的方法:
1.在演示文稿插入图像控件,打开属性窗口,将picture设成你想拖动的图片,遗憾的是Image控件不支持透明。
2. 双击图像控件,打开的VBA编辑窗口(注意双击后已有两行代码,先删除),复制下面的代码:
Dim X1, Y1 As Integer
Dim Down As Boolean
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not Down Then
X1 = X
Y1 = Y
Down = True
End If
End Sub
Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Down Then
Image1.Left = Image1.Left + X - X1
Image1.Top = Image1.Top + Y - Y1
X1 = X
Y1 = Y
End If
End Sub
Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Down = False
SlideShowWindows(1).View.First
End Sub
运行,OK。
代码很简单,如果你想拖动多张图片,如法炮制,复制上面的三个鼠标事件,修改Image1、X1、Y1。
|
|