Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 AutoScrollMargin Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ScrollableControl..::.AutoScrollMargin Property

Gets or sets the size of the auto-scroll margin.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Property AutoScrollMargin As Size
Visual Basic (Usage)
Dim instance As ScrollableControl
Dim value As Size

value = instance.AutoScrollMargin

instance.AutoScrollMargin = value
C#
public Size AutoScrollMargin { get; set; }
Visual C++
public:
property Size AutoScrollMargin {
    Size get ();
    void set (Size value);
}
JScript
public function get AutoScrollMargin () : Size
public function set AutoScrollMargin (value : Size)

Property Value

Type: System.Drawing..::.Size
A Size that represents the height and width of the auto-scroll margin in pixels.
ExceptionCondition
ArgumentOutOfRangeException

The Height or Width value assigned is less than 0.

The auto-scroll margin is the distance between any child controls and the edges of the scrollable parent control. The AutoScrollMargin size is added to the size of any child controls contained in the scrollable control to determine whether or not scroll bars are needed. The AutoScrollMargin property is evaluated when the parent scrollable control is resized or the individual child controls are brought into view, and is used to determine if scroll bars must be displayed. Docked controls are excluded from the calculations that determine if scroll bars must be displayed.

NoteNote:

If a docked control's Dock property is set to DockStyle..::.Fill, the control fills the parent scrollable control and the docked control is ignored when using the AutoScrollMargin to determine whether scroll bars are needed.

If the distance from the edge of a child control to the parent scrollable control is less than the value assigned to the AutoScrollMargin property and the AutoScroll property is set to true, the appropriate scroll bar is displayed.

NoteNote:

We recommend, when docking controls within a scrollable control, that you add a child scrollable control, such as a Panel, to contain any other controls that might require scrolling. You should add the child Panel control to the scrollable control and its Dock property set to DockStyle..::.Fill and its AutoScroll property set to true. You should set the AutoScroll property of the parent scrollable control to false.

The following code 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. The example requires that you have created an instance of a Panel control, TextBox, and Button. Place the text box on the panel so that it overlaps at least one of the panel's edges. Call this function 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);
       }
    }
 }


Visual C++
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 );
      }
   }
}

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker