Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

same scale for picturebox and HScroll1 and VScroll1



Hi,

I have a picturebox that i place objects on it (for example: buttons, label, etc). When I move the object to the bottom right corner of the picturebox, I want it the scrollbars to scroll down or scroll right.

I know that to move the object to the new position, I need to add its current position + value of the scrollbar. However, I might be wrong...

Also, I need to know how to have the same scale for the distance that object moves on the picturebox and the value of the scrollbar (HScroll1.Value and VScroll1.Value)...


I attached my code in case you might need it to help me.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub RoomMouseMoveEvent(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)

    Dim lLeft As Integer
    Dim lTop As Integer
    Dim lWidth As Integer
    Dim lHeight As Integer
           
    'if LEFT mouse button pressed
    If Button = KEY_LBUTTON Then
   
        'position
        lLeft = myMapForm!pnlRoom(Index).Left
        lTop = myMapForm!pnlRoom(Index).Top
       
        'dimentions
        lWidth = myMapForm!pnlRoom(Index).Width
        lHeight = myMapForm!pnlRoom(Index).Height
       
        'new position
        lLeft = (lLeft + x) - mOldX
        lTop = (lTop + y) - mOldY
       
        'check boundries, if we can move the room
        Call CalculateNewPosition(lLeft, lTop, lWidth, lHeight)
        Call SnapToGrid

        'move object. Left, Top, Width, Height
        myMapForm!pnlRoom(Index).Move NewX, NewY
   
    Else
        'do nothing
       
    End If
   
    Dim Position As POINTAPI
    GetCursorPos Position
    myMapConfig.myMainForm!sbStatusBar.Panels(1) = "Room Left -" + Str$(NewX) + " Room Top -" + Str$(NewY) _
    + "     X -" + Str$(x) + " Y -" + Str$(y) + "     MouseX -" + Str$(Position.x) + " MouseY -" + Str$(Position.y)
   
End Sub

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub CalculateNewPosition(ByVal lLeft As Integer, ByVal lTop As Integer, ByVal lWidth As Integer, ByVal lHeight As Integer)
   
    Dim lRight As Integer
    Dim lBottom As Integer
   
    lRight = myMapForm.ScaleWidth - lLeft - lWidth - myMapForm.VScroll1.Width
    lBottom = myMapForm.ScaleHeight - lTop - lHeight - myMapForm.HScroll1.Height
   
    If lRight > 0 And lBottom > 0 Then
   
        If lLeft > 0 And lTop > 0 Then
                       
            NewX = lLeft
            NewY = lTop
 
        ElseIf lLeft <= 0 And lTop > 0 Then
       
            NewX = 0
            NewY = lTop
   
        ElseIf lTop <= 0 And lLeft > 0 Then
           
            NewX = lLeft
            NewY = 0
   
        ElseIf lLeft <= 0 And lTop <= 0 Then
       
            NewX = 0
            NewY = 0
           
        End If

    ElseIf lRight <= 0 And lBottom > 0 Then
        If lTop > 0 Then
       
            NewX = myMapForm.ScaleWidth - lWidth - myMapForm.VScroll1.Width
            NewY = lTop
           
        ElseIf lTop <= 0 Then

            NewX = myMapForm.ScaleWidth - lWidth - myMapForm.VScroll1.Width
            NewY = 0
           
        End If
   
    ElseIf lBottom <= 0 And lRight > 0 Then
       
        If lLeft > 0 Then
           
            NewX = lLeft
            NewY = myMapForm.ScaleHeight - lHeight - myMapForm.HScroll1.Height
           
        ElseIf lLeft <= 0 Then
       
            NewX = 0
            NewY = myMapForm.ScaleHeight - lHeight - myMapForm.HScroll1.Height
           
        End If
    'we are beyond right and bottom boundaries (bottom, right corner)
    ElseIf lRight <= 0 And lBottom <= 0 Then
   
        NewX = myMapForm.ScaleWidth - lWidth - myMapForm.VScroll1.Width
        NewY = myMapForm.ScaleHeight - lHeight - myMapForm.HScroll1.Height
       
    End If
 
    NewX = NewX + myMapForm.HScroll1.Value
    NewY = NewY + myMapForm.VScroll1.Value

   
   
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------



Thanks a lot!

0
TungVan
Asked:
TungVan
  • 2
1 Solution
 
mushu999Commented:
Try this link for the answer you are probably looking for:

http://vbnet.mvps.org/code/forms/scrollviewport.htm

Hope it helps!
0
 
mushu999Commented:
Oh yeah, this link tells you how to maintain aspect ratio while scrolling:

http://vbnet.mvps.org/code/subclass/aspectratio.htm
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now