ScrollableControl.SetAutoScrollMargin(Int32, Int32) 方法

定义

设置自动滚动边距的大小。

C#
public void SetAutoScrollMargin(int x, int y);

参数

x
Int32

Width 值。

y
Int32

Height 值。

示例

下面的代码示例使用派生类 Panel。 该示例计算文本框的位置,并更改其父容器(面板控件)的外观和行为。 该示例要求你已创建控件 的 Panel 实例, TextBoxButton。 将框放在面板上,使其至少与面板的一个边缘重叠。 单击按钮即可调用此子过程,以查看面板行为和外观的差异。

C#
private void MySub()
 {
    /* 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);
       }
    }
 }

注解

边距设置每个控件周围的边框的宽度和高度。 此边距用于确定容器上何时需要滚动条,以及选择控件时滚动到的位置。

备注

如果将负数作为 xy 值传入,则该值将重置为 0。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅