两种方式实现:PPT中实现图片的拖动功能.doc

上传人:sk****8 文档编号:4081142 上传时间:2019-09-24 格式:DOC 页数:4 大小:44.50KB
下载 相关 举报
两种方式实现:PPT中实现图片的拖动功能.doc_第1页
第1页 / 共4页
两种方式实现:PPT中实现图片的拖动功能.doc_第2页
第2页 / 共4页
两种方式实现:PPT中实现图片的拖动功能.doc_第3页
第3页 / 共4页
两种方式实现:PPT中实现图片的拖动功能.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、【PPT 中也能实现图片的拖动功能】本文档内包括两种方法来实现现对 PPT 中如何实现:当播放 PPT 时,能够随意拖动图片到指定位置(补充:通过插入制作好的 FLASH也可以实现这样的效果,后续有时间了会接着发布的,敬请期待)。、一、通过宏实现 PPT 中图片的拖动功能此处建议将宏的安全级别设置为低。1打开你要设置图片拖动功能的 PPT。2点击菜单:“工具宏宏”,出现对话窗口。3填写对话窗口中的“宏名”,宏名可以随意命名,比如:wantmove,再点“创建”,就进入代码模式。4删去所看到的所有的代码,然后把下面的代码全拷贝进去。Option ExplicitDeclare Function

2、GetKeyState Lib “user32“ (ByVal nVirtKey As Long) As IntegerPrivate Declare Function WindowFromPoint Lib “user32“ (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Declare Function GetWindowRect Lib “user32“ (ByVal hwnd As Long, lpRect As RECT) As LongPrivate Declare Function GetCursorPos

3、Lib “user32“ (lpPoint As PointAPI) As LongPrivate Declare Function SetCursorPos Lib “user32“ (ByVal x As Long, ByVal y As Long) As LongPublic Declare Function MonitorFromPoint Lib “user32.dll“ (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As LongPrivate Declare Function GetSystemMetrics

4、Lib “user32“ (ByVal nIndex As Long) As LongPrivate Const SM_SCREENX = 0Private Const SM_SCREENY = 1Private Const sigProc = “Drag & Drop“Public Const VK_SHIFT = &H10Public Const VK_CTRL = &H11Public Const VK_ALT = &H12Private Type PointAPIx As Longy As LongEnd TypePublic Type RECTLeft As LongTop As L

5、ongRight As LongBottom As LongEnd TypePublic mPoint As PointAPI, dPoint As PointAPIPublic ActiveShape As ShapeDim dragMode As BooleanDim dx As Double, dy As DoubleSub DragandDrop(sh As Shape)dragMode = Not dragModeIf dragMode Then Drag shEnd SubPrivate Sub Drag(sh As Shape)Dim i As Integer, sx As In

6、teger, sy As IntegerDim mWnd As Long, WR As RECTdx = GetSystemMetrics(SM_SCREENX): dPoint.x = dxdy = GetSystemMetrics(SM_SCREENY): dPoint.y = dyGetCursorPos mPointWith ActivePresentation.SlideShowWindowmWnd = WindowFromPoint(mPoint.x, mPoint.y)GetWindowRect mWnd, WRsx = WR.Leftsy = WR.Topdx = (WR.Ri

7、ght - WR.Left) / ActivePresentation.PageSetup.SlideWidthdy = (WR.Bottom - WR.Top) / ActivePresentation.PageSetup.SlideHeightEnd WithIf dx dy Thensx = sx + (dx - dy) * ActivePresentation.PageSetup.SlideWidth / 2dx = dyEnd IfIf dy dx Thensy = sy + (dy - dx) * ActivePresentation.PageSetup.SlideHeight /

8、 2dy = dxEnd IfWhile dragModeGetCursorPos mPointsh.Left = (mPoint.x - sx) / dx - sh.Width / 2sh.Top = (mPoint.y - sy) / dy - sh.Height / 2DoEventsi = i + 1: If i 2000 Then dragMode = False: Exit SubWendEnd Sub5点击“保存”后,关闭代码模式,回到 ppt 设计页面。在你需要拖动的图片上鼠标右击,选择 “动作设置单击鼠标运行宏确定”!6放映幻灯片,看看效果吧。拖动图片方式:播放 PPT,在图

9、片上单击鼠标,放开后,图片就随你鼠标移动,如果你再单击鼠标,图片就停在你单击的地方。二、通过 VBA 编实现 PPT 中图片的拖动功能此处建议将宏的安全级别设置为低。1在 演示文稿插入图像控件(视图 工具栏 控件工具箱),打开属性窗口,将 picture 设成你想拖动的图片(图片大小要根据实际情况进行调整),遗憾的是 Image 控件不支持透明。2双击图像控件,打开的 VBA 编辑窗口(注意双击后先删除所有代码),复制下面的代码:Dim X1, Y1 As IntegerDim Down As BooleanPrivate Sub Image1_MouseDown(ByVal Button A

10、s Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)If Not Down ThenX1 = XY1 = YDown = TrueEnd IfEnd SubPrivate Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)If Down ThenImage1.Left = Image1.Left + X - X1Image1.Top = Im

11、age1.Top + Y - Y1X1 = XY1 = YEnd IfEnd SubPrivate Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)Down = FalseSlideShowWindows(1).View.FirstEnd Sub3保存,关闭 VBA 编辑窗口,放映幻灯片,即可看效果了。4如果你想拖动多张图片,如法炮制,复制上面的三个鼠标事件,修改 Image1、X1、Y1 。拖动图片方式:播放 PPT,在图片上按住鼠标,并且要长按住,这样图片才会随你鼠标移动,放开后,图片就停在你放开的地方。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 重点行业资料库 > 自然科学

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。