7.2.3

Returning to figure 7.3, we see that next in the inheritance hierarchy comes Scrol-lableControl. Unlike buttons and list boxes, a form is a scrollable control which means that it supports auto scrolling. The ScrollableControl class contains the public instance boolean AutoScroll property which determines whether the container will allow the user to scroll to controls placed outside its visible boundary. Listing 7.4 illustrates.

Listing 7.4 Coding a scrollable form

// file : scrollform.cs

// compile : csc /t:winexe scrollform.cs

using System;

using System.Drawing;

using System.Windows.Forms;

namespace MyForms {

public class ScrollForm : Form {

public static void Main(string[] args) {

ScrollForm f = new ScrollForm();f.AutoScroll = false; // switch off AutoScroll

f.Text = "AutoScroll Off";

if (args.Length > 0)

if (args[0].ToLower() == "/autoscroll") {

f.AutoScroll = true; // switch on AutoScroll

f.Text = "AutoScroll On";

}

Application.Run(f);

}

public ScrollForm() {

Width = 2 0 0; Height = 2 0 0;

Button b = new Button(); b.Location = new Point(10, 10); b.Size = new Size(300, 30); b.Text = "My Button"; Controls.Add(b);

}