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

屬性值

Size

Size,表示自動捲動邊界的高度和寬度 (以像素為單位)。

例外狀況

指派的 HeightWidth 值小於 0。

範例

下列程式碼範例使用衍生類別 。 Panel 此範例會評估文字方塊的位置,並變更其父容器的外觀和行為,也就是面板控制項。 此範例會要求您已建立 控制項 、 TextBoxButtonPanel 實例。 將文字方塊放在面板上,使其至少重迭其中一個面板邊緣。 按一下按鈕即可呼叫此函式,以查看面板行為和外觀的差異。

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 。 您應該將 AutoScroll 父捲動控制項的 屬性設定為 false

適用於

另請參閱