拖放是用鼠标拖动一个文件到其它对象的活动在图形操作过程中拖放是最常用的功能之一下面我们来看看怎样用VB实现拖放功能 首先介绍与拖放有关的控件 属性DragMode决定拖动操作的初始化是人工方式还是自动方式 DragIcon确定在拖动过程中显示的指针的图标形状 方法Drag开始结束或取消拖动控件 事件MouseDown事件发生于用户按下鼠标按钮时 DragOver事件发生于拖动操作完成时 DragDrop事件发生于拖动操作正在进行时 然后编写一个小程序这个程序能实现在窗口中或窗口间拖动图标的功能建 立窗口Form和Form在窗口中都加入Image其中Form下的Imagepicture为你想显示的图标 Form下程序代码为 Option Explicit Dim dragx As Single Dim dragy As Single Const BEGIN_DRAG= Private Sub Form_DragDrop(Source As Control X As Single Y As Single) ImagePicture=Source ;Sourse为被拖动的控件 FormImagePicture=LoadPicture(″″) ImageMove(Xdragx)(Ydragy) XY为鼠标所在目标窗体或控件的当前坐标 End Sub Private Sub Form_Load() Load Form FormShow End Sub Private Sub Image_MouseDown(Button As IntegerShift As Integer X As SingleY As Single) dragx=X dragy=Y ImageDrag BEGIN_DRAG ;开始拖动操作 ImageDragIcon = LoadPicture(″按下鼠标时想显示的光标″) End Sub Form下程序代码为 Option Explicit Dim dragx As Single Dim dragy As Single Const BEGIN_DRAG= Private Sub Form_DragDrop(Source As ControlX As SingleY As Single) ImagePicture=Source FormImagePicture=LoadPicture(″″) ImageMove(Xdragx)(Ydragy) End Sub Private Sub Image_MouseDown(Button As Integer Shift As Integer源码天空 X As SingleY As Single) dragx=X dragy=Y ImageDrag BEGIN_DRAG ImageDragIcon=LoadPicture(″按下鼠标时想显示的光标″) End Sub 本程序在VBWindow环境下通过 |