10.5. Create a Scrollable Image

Problem

You need to create a scrollable picture.

Solution

Leverage the automatic scroll capabilities of the System.Windows.Forms.Panel control by setting Panel.AutoScroll to True and placing a System.Windows.Forms.PictureBox control with the image content inside the Panel.

How It Works

The Panel control has built-in scrolling support, as shown in recipe 10-1. If you place any controls in it that extend beyond its bounds and you set Panel.AutoScroll to True, the panel will show scroll bars that allow the user to move through the content. This works particularly well with large images. You can load or create the image in memory, assign it to a picture box (which has no intrinsic support for scrolling), and then ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.