ScrollableControl.AutoScrollMargin 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置自动滚动边距的大小。
public:
 property System::Drawing::Size AutoScrollMargin { System::Drawing::Size get(); void set(System::Drawing::Size value); };public System.Drawing.Size AutoScrollMargin { get; set; }member this.AutoScrollMargin : System.Drawing.Size with get, setPublic Property AutoScrollMargin As Size属性值
Size,表示自动滚动边距的高度和宽度(以像素为单位)。
例外
示例
下面的代码示例使用派生类。 Panel 该示例评估文本框的位置,并更改其父容器(面板控件)的外观和行为。 该示例要求你已创建控件的 Panel 实例, TextBox以及 Button。 将文本框放在面板上,使其与面板的边缘至少重叠。 单击按钮可调用此函数,以查看面板的行为和外观的差异。
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 );
      }
   }
}
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);
       }
    }
 }
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
注解
自动滚动边距是任何子控件与可滚动父控件边缘之间的距离。 大小 AutoScrollMargin 将添加到可滚动控件中包含的任何子控件的大小,以确定是否需要滚动条。 AutoScrollMargin当调整父可滚动控件的大小或将单个子控件引入视图中时,将评估该属性,并用于确定是否必须显示滚动条。 停靠控件从计算中排除,以确定是否必须显示滚动条。
备注
如果将停靠控件 Dock 的属性设置为 DockStyle.Fill,则控件将填充父可滚动控件,在使用确定是否需要滚动条时 AutoScrollMargin 忽略停靠控件。
如果子控件边缘到父可滚动控件的距离小于分配给 AutoScrollMargin 属性的值,并且 AutoScroll 该属性设置为 true该值,则会显示相应的滚动条。
备注
我们建议在可滚动控件内停靠控件时,添加子可滚动控件(例如 a Panel)以包含可能需要滚动的任何其他控件。 应将子Panel控件添加到可滚动控件及其属性集,DockStyle.Fill AutoScroll true并将其Dock属性设置为 。 应将 AutoScroll 父可滚动控件的属性设置为 false。