Export (0) Print
Expand All

Form.AutoScroll Property

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

[Visual Basic]
Overrides Public Property AutoScroll As Boolean
[C#]
public override bool AutoScroll {get; set;}
[C++]
public: __property bool get_AutoScroll();
public: __property void set_AutoScroll(bool);
[JScript]
public override function get AutoScroll() : Boolean;
public override function set AutoScroll(Boolean);

Property Value

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

Remarks

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.

Example

[Visual Basic, C#, C++] The following 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 assumes that the method defined in this example is called from another form in an event handler or other method.

[Visual Basic] 
Private Sub DisplayMyScrollableForm()
   ' Create a new form.
   Dim form2 As New Form()
   ' Create a button to add to the new form.
   Dim button1 As 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()
End Sub

[C#] 
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();
}

[C++] 
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 = S"Scrolled Button";
      // Set the size of the button.
      button1->Size = System::Drawing::Size(100,30);
      // Set the location of the button to be outside the form's client area.
      button1->Location = 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();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Form Class | Form Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft