ScrollableControl.SetAutoScrollMargin(Int32, Int32) 方法

定義

設定自動捲動邊界的大小。Sets the size of the auto-scroll margins.

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 值。The Width value.

y
Int32

Height 值。The Height value.

範例

下列程式碼範例會使用衍生的類別 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 控制項、和的實例 TextBox ButtonThe example requires that you have created an instance of a Panel control, TextBox, and Button. 將方塊放在面板上,使其與至少一個面板邊緣重迭。Place the box on the panel so that it overlaps at least one of the panel's edges. 當您按一下按鈕來查看面板的行為和外觀之間的差異時,請呼叫此副程式。Call this subprocedure on the click of a button to see the difference in the panel's behavior and appearance.

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

備註

邊界會在每個控制項周圍設定框線的寬度和高度。The margin sets the width and height of the border around each control. 這個邊界是用來決定何時需要捲軸,以及在選取控制項時要從哪裡滾動。This margin is used to determine when scroll bars are needed on the container and where to scroll to when a control is selected.

注意

如果傳入的負數為 xy 值,則值會重設為0。If a negative number is passed in as the x or y values, the value will be reset to 0.

適用於

另請參閱