两种方式实现:PPT中实现图片的拖动功能Word文档下载推荐.doc
《两种方式实现:PPT中实现图片的拖动功能Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《两种方式实现:PPT中实现图片的拖动功能Word文档下载推荐.doc(4页珍藏版)》请在冰点文库上搜索。
3.填写对话窗口中的“宏名”,宏名可以随意命名,比如:
wantmove,再点“创建”,就进入代码模式。
4.删去所看到的所有的代码,然后把下面的代码全拷贝进去。
OptionExplicit
DeclareFunctionGetKeyStateLib"
user32"
(ByValnVirtKeyAsLong)AsInteger
PrivateDeclareFunctionWindowFromPointLib"
(ByValxPointAsLong,ByValyPointAsLong)AsLong
PrivateDeclareFunctionGetWindowRectLib"
(ByValhwndAsLong,lpRectAsRECT)AsLong
PrivateDeclareFunctionGetCursorPosLib"
(lpPointAsPointAPI)AsLong
PrivateDeclareFunctionSetCursorPosLib"
(ByValxAsLong,ByValyAsLong)AsLong
PublicDeclareFunctionMonitorFromPointLib"
user32.dll"
(ByValxAsLong,ByValyAsLong,ByValdwFlagsAsLong)AsLong
PrivateDeclareFunctionGetSystemMetricsLib"
(ByValnIndexAsLong)AsLong
PrivateConstSM_SCREENX=0
PrivateConstSM_SCREENY=1
PrivateConstsigProc="
Drag&
Drop"
PublicConstVK_SHIFT=&
H10
PublicConstVK_CTRL=&
H11
PublicConstVK_ALT=&
H12
PrivateTypePointAPI
xAsLong
yAsLong
EndType
PublicTypeRECT
LeftAsLong
TopAsLong
RightAsLong
BottomAsLong
PublicmPointAsPointAPI,dPointAsPointAPI
PublicActiveShapeAsShape
DimdragModeAsBoolean
DimdxAsDouble,dyAsDouble
SubDragandDrop(shAsShape)
dragMode=NotdragMode
IfdragModeThenDragsh
EndSub
PrivateSubDrag(shAsShape)
DimiAsInteger,sxAsInteger,syAsInteger
DimmWndAsLong,WRAsRECT
dx=GetSystemMetrics(SM_SCREENX):
dPoint.x=dx
dy=GetSystemMetrics(SM_SCREENY):
dPoint.y=dy
GetCursorPosmPoint
WithActivePresentation.SlideShowWindow
mWnd=WindowFromPoint(mPoint.x,mPoint.y)
GetWindowRectmWnd,WR
sx=WR.Left
sy=WR.Top
dx=(WR.Right-WR.Left)/ActivePresentation.PageSetup.SlideWidth
dy=(WR.Bottom-WR.Top)/ActivePresentation.PageSetup.SlideHeight
EndWith
Ifdx>
dyThen
sx=sx+(dx-dy)*ActivePresentation.PageSetup.SlideWidth/2
dx=dy
EndIf
Ifdy>
dxThen
sy=sy+(dy-dx)*ActivePresentation.PageSetup.SlideHeight/2
dy=dx
WhiledragMode
GetCursorPosmPoint
sh.Left=(mPoint.x-sx)/dx-sh.Width/2
sh.Top=(mPoint.y-sy)/dy-sh.Height/2
DoEvents
i=i+1:
Ifi>
2000ThendragMode=False:
ExitSub
Wend
5.点击“保存”后,关闭代码模式,回到ppt设计页面。
在你需要拖动的图片上鼠标右击,选择“动作设置——单击鼠标——运行宏——确定”!
6.放映幻灯片,看看效果吧。
拖动图片方式:
播放PPT,在图片上单击鼠标,放开后,图片就随你鼠标移动,如果你再单击鼠标,图片就停在你单击的地方。
二、通过VBA编实现PPT中图片的拖动功能
1.在演示文稿插入图像控件(视图——工具栏——控件工具箱),打开属性窗口,将picture设成你想拖动的图片(图片大小要根据实际情况进行调整),遗憾的是Image控件不支持透明。
2.双击图像控件,打开的VBA编辑窗口(注意双击后先删除所有代码),复制下面的代码:
DimX1,Y1AsInteger
DimDownAsBoolean
PrivateSubImage1_MouseDown(ByValButtonAsInteger,ByValShiftAsInteger,ByValXAsSingle,ByValYAsSingle)
IfNotDownThen
X1=X
Y1=Y
Down=True
PrivateSubImage1_MouseMove(ByValButtonAsInteger,ByValShiftAsInteger,ByValXAsSingle,ByValYAsSingle)
IfDownThen
Image1.Left=Image1.Left+X-X1
Image1.Top=Image1.Top+Y-Y1
PrivateSubImage1_MouseUp(ByValButtonAsInteger,ByValShiftAsInteger,ByValXAsSingle,ByValYAsSingle)
Down=False
SlideShowWindows
(1).View.First
3.保存,关闭VBA编辑窗口,放映幻灯片,即可看效果了。
4.如果你想拖动多张图片,如法炮制,复制上面的三个鼠标事件,修改Image1、X1、Y1。
播放PPT,在图片上按住鼠标,并且要长按住,这样图片才会随你鼠标移动,放开后,图片就停在你放开的地方。