ScrollableControl.AutoScrollMargin 属性

定义

获取或设置自动滚动边距的大小。Gets or sets the size of the auto-scroll margin.

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, set
Public Property AutoScrollMargin As Size

属性值

Size,表示自动滚动边距的高度和宽度(以像素为单位)。A Size that represents the height and width of the auto-scroll margin in pixels.

异常

分配的 HeightWidth 值小于 0。The Height or Width value assigned is less than 0.

示例

下面的代码示例使用派生类PanelThe following code example uses the derived class, Panel. 该示例将计算文本框的位置,并更改其父容器(panel 控件)的外观和行为。The example evaluates the location of a text box and changes the appearance and behavior of its parent container, the panel control. 该示例要求您已经创建了一个Panel控件、 TextBoxButton的实例。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.

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

注解

自动滚动边距是任何子控件和可滚动父控件边缘之间的距离。The auto-scroll margin is the distance between any child controls and the edges of the scrollable parent control. AutoScrollMargin大小添加到可滚动控件中包含的任何子控件的大小,以确定是否需要滚动条。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. 当调整父可滚动控件的大小时,或将各个子控件置于视图中时,将计算属性,并使用来确定是否必须显示滚动条。AutoScrollMarginThe 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.

备注

如果停靠控件的Dock属性设置为,则在使用AutoScrollMargin确定是否需要滚动条时,控件将填充父可DockStyle.Fill滚动控件并忽略停靠的控件。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.

如果从子控件的边缘到父可滚动控件的距离小于分配给该AutoScrollMargin属性的值, AutoScroll并且属性设置为true,则会显示相应的滚动条。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.

备注

建议在可滚动控件内停靠控件时,添加一个子可滚动控件(如Panel),以包含可能需要滚动的任何其他控件。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. Panel将子控件添加到可滚动的控件,并Dock将其属性DockStyle.Fill设置为AutoScroll ,并将true其属性设置为。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. 应将父可AutoScroll滚动控件的属性设置为。 falseYou should set the AutoScroll property of the parent scrollable control to false.

适用于

另请参阅