当我使用水平和垂直滚动条时,我有滚动的图像.但我想像在Photoshop中一样拖动图像(使用手工工具并通过缩放图像进行探索).在Visual Basic 6.0中有没有办法这样做?我已将鼠标的默认光标更
从MouseDown事件开始.在这里,您需要检查哪个按钮处于关闭状态(如果您只允许使用左按钮,左右按钮或右按钮进行拖动),请将鼠标光标更改为关闭或折叠的手(指示拖动正在进行中),并设置一些跟踪光标起始坐标的成员变量.例:
Private Sub picBox_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) ' When left mouse button is pressed down (initiating a drag) If Button = 1 Then ' Store the coordinates of the mouse cursor xpos = x ypos = y ' Change the cursor to hand grab icon picBox.MouseIcon = LoadPicture(App.Path & "\Resources\Cursors\grab.ico") End If End Sub
然后,您将处理MouseMove事件,您将在其中执行实际拖动(在图片框内移动图像).在这个例子中,我选择简单地在容器Form上移动整个图片框控件,而不是在图片框内移动图像.您可能需要在此处更改逻辑,具体取决于表单的布局和您的特定需求.例如,你说你有滚动条 – 在这种情况下,你需要在这里调整X和Y滚动条的位置.
Private Sub picBox_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) ' When left mouse button is being held down (drag) If Button = 1 Then ' Drag the picture box around the form picBox.Move x + (picBox.Left - xpos), y + (picBox.Top - ypos) End If End Sub
最后,您需要处理MouseUp事件,您将通过重置光标来结束拖动:
Private Sub picBox_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) ' Stop normal dragging If Button = 1 Then ' Set the cursor back to the unclapsed hand picBox.MouseIcon = LoadPicture(App.Path & "\Resources\Cursors\hand.ico") End If End Sub
当然,您需要将这些成员变量添加到Form类的顶部,以跟踪光标的先前位置(在x和y坐标中).像这样简单的事情会:
Private xpos As Long Private ypos As Long
游标看起来像这样,类似于你在Adobe Acrobat或Mac OS 9中发现的(可能最初是由像Susan Kare这样神奇的人绘制的;可能不属于公共领域):