这是在窗体中移动一个按钮的代码 只是说明一下问题: Option Explicit Dim Cx As Single Dim Cy As Single
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Cx = Command1.Left Cy = Command1.Top End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Command1.Move Cx + X, Cy + Y End Sub
那是mousemove事件又不是drag事件。。要处理拖动事件最好是用 mousedown事件开启你所点控件的drag( 控件.drag 1) 然后用dragdrop事件来处理。DragDrop 事件 在一个完整的拖放动作(即将一个控件拖动到一个对象上,并释放鼠标按钮)完成,或使用 Drag 方法,并将其 action 参数被设置为 2 (Drop) 时,该事件发生。语法Private Sub Form_DragDrop(source As Control, x As Single, y As Single)Private Sub MDIForm_DragDrop(source As Control, x As Single, y As Single)Private Sub object_DragDrop([index As Integer,]source As Control, x As Single, y As Single)DragDrop 事件语法包含下列部分:部分 描述 object 一个对象表达式,其值是“应用于”列表中的一个对象。 index 一个整数,用来唯一地标识一个在控件数组中的控件。 source 正在被拖动的控件。可用此参数将属性和方法包括在事件过程中 — 例如,Source.Visible = 0。 x, y 是一个指定当前鼠标指针在目标窗体或控件中水平 (x) 和垂直 (y) 位置的数字。这些坐标值通常用目标坐标系统来表示,该坐标系是通过 ScaleHeight、ScaleWidth、ScaleLeft 和 ScaleTop 属性而设置的。 说明DragDrop 事件过程用来控制在一个拖动操作完成时将会发生的情况。例如,可将源控件移到一个新的位置或将一个文件从一个位置复制到另一个位置。当 source 参数中可能使用多个控件时: 应使用 TypeOf 关键字和 If 语句一起确定与 source 表示的控件的类型。 应使用该控件的 Tag 属性来标识一个控件,然后使用 DragDrop 事件过程。 注意 应使用 DragMode 属性和 Drag 方法来指定开始拖动的方法。一旦开始拖动,可使用 DragOver 事件过程来处理位于 DragDrop 事件前面的事件。
只是说明一下问题:
Option Explicit
Dim Cx As Single
Dim Cy As Single
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Cx = Command1.Left
Cy = Command1.Top
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Move Cx + X, Cy + Y
End Sub
mousedown事件开启你所点控件的drag( 控件.drag 1)
然后用dragdrop事件来处理。DragDrop 事件
在一个完整的拖放动作(即将一个控件拖动到一个对象上,并释放鼠标按钮)完成,或使用 Drag 方法,并将其 action 参数被设置为 2 (Drop) 时,该事件发生。语法Private Sub Form_DragDrop(source As Control, x As Single, y As Single)Private Sub MDIForm_DragDrop(source As Control, x As Single, y As Single)Private Sub object_DragDrop([index As Integer,]source As Control, x As Single, y As Single)DragDrop 事件语法包含下列部分:部分 描述
object 一个对象表达式,其值是“应用于”列表中的一个对象。
index 一个整数,用来唯一地标识一个在控件数组中的控件。
source 正在被拖动的控件。可用此参数将属性和方法包括在事件过程中 — 例如,Source.Visible = 0。
x, y 是一个指定当前鼠标指针在目标窗体或控件中水平 (x) 和垂直 (y) 位置的数字。这些坐标值通常用目标坐标系统来表示,该坐标系是通过 ScaleHeight、ScaleWidth、ScaleLeft 和 ScaleTop 属性而设置的。
说明DragDrop 事件过程用来控制在一个拖动操作完成时将会发生的情况。例如,可将源控件移到一个新的位置或将一个文件从一个位置复制到另一个位置。当 source 参数中可能使用多个控件时: 应使用 TypeOf 关键字和 If 语句一起确定与 source 表示的控件的类型。
应使用该控件的 Tag 属性来标识一个控件,然后使用 DragDrop 事件过程。
注意 应使用 DragMode 属性和 Drag 方法来指定开始拖动的方法。一旦开始拖动,可使用 DragOver 事件过程来处理位于 DragDrop 事件前面的事件。
不过有点担心是不是mousemove事件能地拖动时检测到。
你试试吧我手头没有VB不能试。