Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user scroll a picture using arrow keys
Keywordsscrolled window, scroll, arrow keys
CategoriesControls
 
Place the picture in a PictureBox inside another PictureBox. In the form's KeyDown event handler, change the inner PictureBox's Left and Top properties to move the inner picture. Note that the keyboard ocntinues sending KeyDown events as long as youhold an arrow key down.
 
Private m_VValue As Single
Private m_VMin As Single
Private m_VMax As Single
Private m_VLargeChange As Single
Private m_VSmallChange As Single

Private m_HValue As Single
Private m_HMin As Single
Private m_HMax As Single
Private m_HLargeChange As Single
Private m_HSmallChange As Single

Private Sub SetScrollingValues()
    ' Set scroll values.
    m_VMax = 0
    m_VMin = OuterPict.ScaleHeight - InnerPict.Height
    m_VLargeChange = OuterPict.ScaleY(20, vbPixels, _
        OuterPict.ScaleMode)
    m_VSmallChange = OuterPict.ScaleY(2, vbPixels, _
        OuterPict.ScaleMode)

    m_HMax = 0
    m_HMin = OuterPict.ScaleWidth - InnerPict.Width
    m_HLargeChange = OuterPict.ScaleX(20, vbPixels, _
        OuterPict.ScaleMode)
    m_HSmallChange = OuterPict.ScaleX(2, vbPixels, _
        OuterPict.ScaleMode)
End Sub

Private Sub Form_Resize()
    OuterPict.Move 0, 0, ScaleWidth, ScaleHeight

    SetScrollingValues
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As _
    Integer)
    Select Case KeyCode
        Case vbKeyDown
            If Shift And vbShiftMask Then
                m_VValue = m_VValue - m_VLargeChange
            Else
                m_VValue = m_VValue - m_VSmallChange
            End If
            If m_VValue < m_VMin Then m_VValue = m_VMin
            InnerPict.Top = m_VValue
        Case vbKeyUp
            If Shift And vbShiftMask Then
                m_VValue = m_VValue + m_VLargeChange
            Else
                m_VValue = m_VValue + m_VSmallChange
            End If
            If m_VValue > m_VMax Then m_VValue = m_VMax
            InnerPict.Top = m_VValue
        Case vbKeyLeft
            If Shift And vbShiftMask Then
                m_HValue = m_HValue + m_HLargeChange
            Else
                m_HValue = m_HValue + m_HSmallChange
            End If
            If m_HValue > m_HMax Then m_HValue = m_HMax
            InnerPict.Left = m_HValue
        Case vbKeyRight
            If Shift And vbShiftMask Then
                m_HValue = m_HValue - m_HLargeChange
            Else
                m_HValue = m_HValue - m_HSmallChange
            End If
            If m_HValue < m_HMin Then m_HValue = m_HMin
            InnerPict.Left = m_HValue
    End Select
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated