共用方式為


ScrollableControl.AutoScrollMargin 屬性

定義

設定自動捲動邊距的大小。

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

屬性值

A Size 代表自動捲動邊距的高度與寬度(像素單位)。

例外狀況

分配的 Height or Width 值小於 0。

範例

以下程式碼範例使用導出類別 Panel。 範例中評估文字框的位置,並改變其父容器面板控制項的外觀與行為。 範例要求你建立一個控制點實例 PanelTextBoxButton。 將文字框放置在面板上,使其至少重疊於面板的其中一個邊緣。 只需點擊按鈕即可呼叫此函式,即可查看面板行為與外觀的差異。

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

備註

自動捲動邊距是指任何子控制項與可捲動父控制項邊緣之間的距離。 AutoScrollMargin大小會加到可捲動控制項中任何子控制項的大小,以判斷是否需要捲動條。 AutoScrollMargin當父捲動控制項大小調整或將個別子控制項移入視野時,會評估此屬性,並用以判斷是否必須顯示捲動條。 停靠控制項不包含在是否必須顯示滾動條的計算範圍。

備註

如果停靠控制項 Dock 的屬性設為 DockStyle.Fill,該控制項會填滿父捲動控制項,且在使用時 AutoScrollMargin 會忽略停靠控制項,以判斷是否需要捲動條。

如果子控制項邊緣到父可捲動控制項的距離小於該屬性所指派 AutoScrollMargin 的值,且 AutoScroll 屬性設為 true,則會顯示相應的捲動條。

備註

我們建議在可捲動控制項中停靠時,加入子捲動控制項,例如 Panel,以包含可能需要捲動的其他控制項。 你應該把子 Panel 控制項加到可滾動控制項,並將 Dock 其屬性設為 , DockStyle.Fill 屬性 AutoScroll 設為 true。 你應該將父可滾動控制項的屬性設 AutoScrollfalse

適用於

另請參閱