ScrollableControl.AutoScrollMargin 屬性

定義

取得或設定自動捲動邊界的大小。Gets or sets the size of the auto-scroll margin.

public:
 property System::Drawing::Size AutoScrollMargin { System::Drawing::Size get(); void set(System::Drawing::Size value); };
public System.Drawing.Size AutoScrollMargin { get; set; }
member this.AutoScrollMargin : System.Drawing.Size with get, set
Public Property AutoScrollMargin As Size

屬性值

Size,表示自動捲動邊界的高度和寬度 (以像素為單位)。A Size that represents the height and width of the auto-scroll margin in pixels.

例外狀況

指派的 HeightWidth 值小於 0。The Height or Width value assigned is less than 0.

範例

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

void SetAutoScrollMargins()
{
   /* 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 SetAutoScrollMargins()
 {
    /* 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 SetAutoScrollMargins()
    ' 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 auto-scroll margin is the distance between any child controls and the edges of the scrollable parent control. AutoScrollMargin大小會加入至可滾動控制項中包含之任何子控制項的大小,以決定是否需要捲軸。The AutoScrollMargin size is added to the size of any child controls contained in the scrollable control to determine whether or not scroll bars are needed. AutoScrollMargin屬性會在父自動滾動控制項調整大小時,或個別子控制項進入視圖時進行評估,並用於判斷是否必須顯示捲軸。The AutoScrollMargin property is evaluated when the parent scrollable control is resized or the individual child controls are brought into view, and is used to determine if scroll bars must be displayed. 停駐的控制項會從計算中排除,以決定是否必須顯示捲軸。Docked controls are excluded from the calculations that determine if scroll bars must be displayed.

注意

如果停駐控制項的Dock屬性設為, DockStyle.Fill控制項就會填滿父系的可滾動控制項,並在使用AutoScrollMargin來判斷是否需要捲軸時,忽略停駐的控制項。If a docked control's Dock property is set to DockStyle.Fill, the control fills the parent scrollable control and the docked control is ignored when using the AutoScrollMargin to determine whether scroll bars are needed.

如果從子控制項邊緣到父系可滾動控制項的距離小於指派AutoScrollMargin給屬性的值AutoScroll ,且屬性設定為true,則會顯示適當的捲軸。If the distance from the edge of a child control to the parent scrollable control is less than the value assigned to the AutoScrollMargin property and the AutoScroll property is set to true, the appropriate scroll bar is displayed.

注意

建議您在可滾動控制項內停駐控制項時,加入子滾動控制項(例如Panel),以包含任何可能需要滾動的其他控制項。We recommend, when docking controls within a scrollable control, that you add a child scrollable control, such as a Panel, to contain any other controls that might require scrolling. 您應該將子Panel控制項加入至可滾動控制項,並將其Dock屬性DockStyle.Fill設定為AutoScroll ,並將true其屬性設定為。You should add the child Panel control to the scrollable control and its Dock property set to DockStyle.Fill and its AutoScroll property set to true. 您應該將父系AutoScroll可滾動控制項的屬性設為falseYou should set the AutoScroll property of the parent scrollable control to false.

適用於

另請參閱