This documentation is archived and is not being maintained.

ScrollableControl.AutoScroll Property

Gets or sets a value indicating whether the container will allow the user to scroll to any controls placed outside of its visible boundaries.

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

Property Value

true if the container allows auto-scrolling; otherwise, false. The default value is false.

Remarks

When true, this property allows the container to have a virtual size that is larger than its visible boundaries.

Example

[Visual Basic, C#, C++] The following example uses the derived class, Panel. The example evaluates the location of a text box and changes the appearance and behavior of its parent container, the panel control. This example assumes a Panel control, TextBox, and Button have been instantiated. Place the text box on the panel so that it overlaps at least one of the panel's edges. Call this subprocedure on the click of a button to see the difference in the panel's behavior and appearance.

[Visual Basic] 
Private Sub SetAutoScrollMargins()
    ' If the text box is outside the panel's bounds,
    ' turn on auto-scrolling and set the margin. 
    If (text1.Location.X > panel1.Location.X) Or _
        (text1.Location.Y > panel1.Location.Y) Then
        panel1.AutoScroll = True
        ' If the AutoScrollMargin is set to less
        ' than (5,5), set it to 5,5. 
        If (panel1.AutoScrollMargin.Width < 5) Or _
            (panel1.AutoScrollMargin.Height < 5) Then
            
            panel1.SetAutoScrollMargin(5, 5)
        End If
    End If
End Sub


[C#] 
private void SetAutoScrollMargins()
 {
    /* If the text box is outside the panel's bounds, 
       turn on auto-scrolling and set the margin. */  
    if (text1.Location.X > panel1.Location.X || 
       text1.Location.Y > panel1.Location.Y)
    {
       panel1.AutoScroll = true;
       /* If the AutoScrollMargin is set to less 
          than (5,5), set it to 5,5. */
       if( panel1.AutoScrollMargin.Width < 5 || 
          panel1.AutoScrollMargin.Height < 5)
       {
          panel1.SetAutoScrollMargin(5, 5);
       }
    }
 }
 

[C++] 
private:
void SetAutoScrollMargins()
 {
    /* If the text box is outside the panel's bounds, 
       turn on auto-scrolling and set the margin. */  
    if (text1->Location.X > panel1->Location.X || 
       text1->Location.Y > panel1->Location.Y)
    {
       panel1->AutoScroll = true;
       /* If the AutoScrollMargin is set to less 
          than (5,5), set it to 5,5. */
       if( panel1->AutoScrollMargin.Width < 5 || 
          panel1->AutoScrollMargin.Height < 5)
       {
          panel1->SetAutoScrollMargin(5, 5);
       }
    }
 }
 

[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

ScrollableControl Class | ScrollableControl Members | System.Windows.Forms Namespace | AutoScrollMargin | AutoScrollPosition | AutoScrollMinSize

Show: