?
Solved

Scrolling image control inside picture box

Posted on 2006-06-02
2
Medium Priority
?
303 Views
Last Modified: 2010-04-07
hello.
I am trying to scroll image control inside picture box, I have done it with horizontal and vertical scroll but now I want to do it also when user press a button on image control and drag it, just like in ACDSee when you load large image.

My problem is when I drag over the image the image is not moved proportionally with cursor movement. This is what I have done till now

In module:
Public press As Byte
Public oX, oY As Long

In Form:
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    oX = X
    oY = Y
    press = 1
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
if press = 1 Then

' I guess the problem solution lies here

    Image1.Left = X - oX
    Image1.Top = Y - oY
end if
End Sub

Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
press = 0
End Sub

Thanks.
0
Comment
Question by:damirsel
2 Comments
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 200 total points
ID: 16816064
>>' I guess the problem solution lies here
>>
>>    Image1.Left = X - oX
>>    Image1.Top = Y - oY


try these 2 lines instead:

    Image1.Left = Image1.Left + X - oX
    Image1.Top = Image1.Top + Y - oY
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16816684
*** Not for points ***  Mark has answered already...

In my opinion, the code looks cleaner this way:

Public oX As Long
Public oY As Long

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    oX = X
    oY = Y
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Image1.Move Image1.Left + X - oX, Image1.Top + Y - oY
    End If
End Sub
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question