通过拖动鼠标滚动图像
当我使用水平和垂直滚动条时,我的图像会滚动。但我想像在 Photoshop 中一样通过拖动来滚动图像(使用手动工具并浏览缩放图像)。在 Visual Basic 6.0 中有没有办法这样做?我已将鼠标的默认光标更改为手形光标。现在我只想通过拖动图像来滚动。
I have the image that scroll when i used the horizontal and vertical scroll bars. But I want to scroll the image by dragging it like in Photoshop (using hand tool and exploring through the zoomed image). Is there any way to do in such way in Visual Basic 6.0? I have changed the default cursor of the mouse to the hand cursor. Now i just want to scroll by dragging the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很简单,您只需处理包含图像的控件的鼠标事件。我将使用我编写的应用程序中的生产代码逐步引导您完成此完全相同的功能。
从
MouseDown
事件开始。在这里,您需要检查哪个按钮被按下(如果您想允许仅使用左键、左右键或仅右键进行拖动),请将鼠标光标更改为握紧或拍掌的手(表明正在进行拖动),并设置一些成员变量来跟踪光标的起始坐标。示例:然后,您将处理
MouseMove
事件,在其中进行实际的拖动(在图片框中移动图像)。在示例中,我选择简单地在容器窗体上移动整个图片框控件,而不是移动图片框内的图像。您可能需要更改此处的逻辑,具体取决于表单的布局和您的特定需求。例如,您说您有滚动条,在这种情况下,您需要在此处调整 X 和 Y 滚动条的位置。最后,您需要处理
MouseUp
事件,在该事件中您将通过重置光标来结束拖动:当然,您需要将这些成员变量添加到 Form 类的顶部跟踪光标之前的位置(以 x 和 y 坐标表示)。像这样简单的事情就可以做到:
看起来像这样,类似于您在 Adobe Acrobat 或 Mac OS 9 中找到的内容(可能最初是由像 Susan Kare 这样的神奇人绘制的;可能不属于公共领域):
光标 ;
Simple, you just need to handle the mouse events for the control that contains your image. I'll walk you through step-by-step using production code from an app I wrote that implements this exact same feature.
Start with the
MouseDown
event. Here, you'll need to check which button is down (if you want to allow dragging with only the left button, both the left and right buttons, or just the right button), change the mouse cursor to a closed or clapsed hand (indicating that a drag is in progress), and set some member variables that keep track of the starting coordinates of the cursor. Example:Then, you'll handle the
MouseMove
event, where you'll do the actual dragging (moving the image inside the picture box). In the example, I chose to simply move the entire picture box control around on the container Form, rather than moving the image inside of the picture box. You might need to change the logic here, depending on the layout of your form and your specific needs. For example, you say that you have scroll bars—in that case, you'll need to adjust the position of the X and Y scroll bars here.And finally, you need to handle the
MouseUp
event, where you'll end the drag by resetting the cursor:And of course, you'll need to add those member variables to the top of your Form class that keep track of the previous position of the cursor (in x and y coordinates). Something as simple as this will do:
The cursors looked something like this, similar to what you'd find in Adobe Acrobat or Mac OS 9 (probably originally drawn by someone magical like Susan Kare; may not be in the public domain):