Export (0) Print
Expand All

Form.AutoScroll Property

Gets or sets a value indicating whether the form enables autoscrolling.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[LocalizableAttribute(true)] 
public override bool AutoScroll { get; set; }
/** @property */
public boolean get_AutoScroll ()

/** @property */
public void set_AutoScroll (boolean value)

public override function get AutoScroll () : boolean

public override function set AutoScroll (value : boolean)

Property Value

true to enable autoscrolling on the form; otherwise, false. The default is false.

If this property is set to true, scroll bars are displayed on the form if any controls are located outside the form's client region. Additionally, when autoscrolling is on, the client area of the form automatically scrolls to make the control with input focus visible.

You can use this property to prevent users from losing the ability to view controls when their video resolution settings are set to a low resolution.

The following code example demonstrates how to use the AutoScroll property to enable the display of controls that are outsize the client area of a form. The example creates a new form and adds a Button control to the form. The Button control is positioned outsize the client area of the new form. The AutoScroll property is set to true to display scroll bars on the form to enable the user to scroll to the control. This example requires that the method defined in this example is called from another form in an event handler or other method.

private void DisplayMyScrollableForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Create a button to add to the new form.
   Button button1 = new Button();
   // Set text for the button.
   button1.Text = "Scrolled Button";
   // Set the size of the button.
   button1.Size = new Size(100,30);
   // Set the location of the button to be outside the form's client area.
   button1.Location = new Point(form2.Size.Width + 200, form2.Size.Height + 200);

   // Add the button control to the new form.
   form2.Controls.Add(button1);
   // Set the AutoScroll property to true to provide scrollbars.
   form2.AutoScroll = true;

   // Display the new form as a dialog box.
   form2.ShowDialog();
}

private void DisplayMyScrollableForm()
{
    // Create a new form.
    Form form2 = new Form();

    // Create a button to add to the new form.
    Button button1 = new Button();

    // Set text for the button.
    button1.set_Text("Scrolled Button");

    // Set the size of the button.
    button1.set_Size(new Size(100, 30));

    // Set the location of the button to be outside the form's client area.
    button1.set_Location(new Point(form2.get_Size().get_Width() + 200, 
        form2.get_Size().get_Height() + 200));

    // Add the button control to the new form.
    form2.get_Controls().Add(button1);

    // Set the AutoScroll property to true to provide scrollbars.
    form2.set_AutoScroll(true);

    // Display the new form as a dialog box.
    form2.ShowDialog();       
} //DisplayMyScrollableForm  

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft