ScrollableControl.SetAutoScrollMargin(Int32, Int32) 方法

定义

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

public:
 void SetAutoScrollMargin(int x, int y);
public void SetAutoScrollMargin (int x, int y);
member this.SetAutoScrollMargin : int * int -> unit
Public Sub SetAutoScrollMargin (x As Integer, y As Integer)

参数

x
Int32

Width 值。

y
Int32

Height 值。

示例

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

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.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 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

注解

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

注意

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

适用于

另请参阅