ScrollableControl.SetAutoScrollMargin(Int32, Int32) 方法

定義

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

C#
public void SetAutoScrollMargin(int x, int y);

參數

x
Int32

Width 值。

y
Int32

Height 值。

範例

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

C#
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);
       }
    }
 }

備註

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

備註

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱