Creating Scrollable Forms


A scrollable form is one that can display scrollbars when its contents are larger than the physical size of the form. Earlier versions of the Visual C# form engine lacked the capability to create scrollable forms. It seems odd that this has never been possible before, and I'm personally happy to see this feature added. Not only is this a great feature, it's also trivial to implement in your own applications.

The scrolling behavior of a form is determined by the following three properties:

Property

Description

AutoScroll

This property determines whether scrollbars will ever appear on a form.

AutoScrollMinSize

The minimum size of the scroll region (area). If the size of the form is adjusted so that the client area of the form (the area of the form not counting borders and title bar) is smaller than the AutoScrollMinSize, scrollbars will appear.

AutoScrollMargin

This property determines the margin given around controls during scrolling. This essentially determines how far past the edge of the outermost controls you can scroll.


Press F5 to run your project now and size the form smaller than it is by dragging the lower-right corner toward the upper-left. Notice that, although the controls adjust themselves the best they can, some controls disappear from view completely as the form gets smaller. The only way you can access these controls is to make the form bigger againunless you make this form a scrollable form.

Follow these steps:

1.

If the project is still running, stop it now.

2.

Set the AutoScroll property of the frmViewer.cs form to True.

3.

Press F5 to run the project.

4.

Drag the lower-right corner of the form toward the upper-left to make the form smaller. Notice that as you do so, a scrollbar appears on the form (see Figure 6.18). You can use the scrollbar to scroll the contents of the form and access controls that would otherwise be unavailable.

Figure 6.18. Without scroll-bars, it's possible to have controls that can't be seen.


Stop the project now and save your work.




Sams Teach Yourself Microsoft Visual C# 2005 in 24 Hours, Complete Starter Kit
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
ISBN: 0672327406
EAN: 2147483647
Year: N/A
Pages: 248
Authors: James Foxall

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net