ScrollableControl.SetAutoScrollMargin 方法

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub SetAutoScrollMargin ( _
    x As Integer, _
    y As Integer _
)
用法
Dim instance As ScrollableControl
Dim x As Integer
Dim y As Integer

instance.SetAutoScrollMargin(x, y)
public void SetAutoScrollMargin (
    int x,
    int y
)
public:
void SetAutoScrollMargin (
    int x, 
    int y
)
public void SetAutoScrollMargin (
    int x, 
    int y
)
public function SetAutoScrollMargin (
    x : int, 
    y : int
)

参数

备注

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

提示

如果传入一个负数作为 x 或 y 的值,则该值会重置为 0。

示例

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

Private Sub 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) 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
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);
       }
    }
 }
 
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 );
      }
   }
}
private void MySub()
{
    /* If the text box is outside the panel's bounds, 
       turn on auto-scrolling and set the margin. 
     */
    if (text1.get_Location().get_X() > panel1.get_Location().get_X() 
        || text1.get_Location().get_Y() > panel1.get_Location().get_Y()) {
            panel1.set_AutoScroll(true);

        /* If the AutoScrollMargin is set to 
           less than (5,5), set it to 5,5. 
         */
        if (panel1.get_AutoScrollMargin().get_Width() < 5 
            || panel1.get_AutoScrollMargin().get_Height() < 5) {
                panel1.SetAutoScrollMargin(5, 5);
        }
    }
} //MySub

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ScrollableControl 类
ScrollableControl 成员
System.Windows.Forms 命名空间
AutoScrollMargin
AutoScroll
AutoScrollMinSize