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 此範例會評估文字方塊的位置,並變更其父容器的外觀和行為,也就是面板控制項。 此範例會要求您已建立 控制項 TextBox 、 和 ButtonPanel 實例。 將方塊放在面板上,使其至少與面板的其中一個邊緣重迭。 按一下按鈕即可呼叫此副程式,以查看面板行為和外觀的差異。

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

備註

邊界會設定每個控制項周圍的框線寬度和高度。 此邊界可用來判斷容器上何時需要捲軸,以及選取控制項時要捲動的位置。

注意

如果以 或 y 值的形式傳入 x 負數,該值將會重設為 0。

適用於

另請參閱