Scrolling View Port Demo

Forms and Controls

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
This is how to create a scrolling view port using PictureBoxes and Scroll Bars. This is handy when you have an image that is too big to be seen at one time, or too many controls that can fit on a form.

For the demo to work, do the following

  1. Start a new project.
  2. On Form1 put a VScrollBar and a PictureBox
  3. Inside of the PictureBox put a second PictureBox.
  4. Don't worry about sizing them. That will be taken care of in code.
  5. Put a command button inside Picture2.
  6. Copy the code below into Form1 declarations section. It will become the Form1_Resize() event and the Vscroll1_Cahnge() event.
  7. Press F5 to run the program. When you scroll the scroll bar the command button should scroll out of site.
The key is to make sure that the second PictureBox is contained in the first PictureBox. All controls or images that you want to scroll must be contained in the second PictureBox.

Instructions: Copy the declarations and code below and paste directly into your VB project.