ScrollableControl.ScrollControlIntoView(Control) 方法

定義

將指定的子控制項捲動至已啟用自動捲動之控制項的檢視中。Scrolls the specified child control into view on an auto-scroll enabled control.

public:
 void ScrollControlIntoView(System::Windows::Forms::Control ^ activeControl);
public void ScrollControlIntoView (System.Windows.Forms.Control activeControl);
member this.ScrollControlIntoView : System.Windows.Forms.Control -> unit
Public Sub ScrollControlIntoView (activeControl As Control)

參數

activeControl
Control

要捲動至檢視中的子控制項。The child control to scroll into view.

範例

下列程式碼範例會啟用表單的自動滾動、調整表單的大小,並確保在調整大小表單之後,按鈕會保持可見。The following code example enables auto-scrolling for a form, resizes the form, and ensures that a button remains visible after the form is resized. 此範例會要求您在 Form Button 其上使用命名 button2The example requires that you have a Form with a Button named button2 on it.

private:
   void ResizeForm()
   {
      
      // Enable auto-scrolling for the form.
      this->AutoScroll = true;
      
      // Resize the form.
      Rectangle r = this->ClientRectangle;
      
      // Subtract 100 pixels from each side of the Rectangle.
      r.Inflate(  -100, -100 );
      this->Bounds = this->RectangleToScreen( r );
      
      // Make sure button2 is visible.
      this->ScrollControlIntoView( button2 );
   }
private void ResizeForm()
{
   // Enable auto-scrolling for the form.
   this.AutoScroll = true;

   // Resize the form.
   Rectangle r = this.ClientRectangle;
   // Subtract 100 pixels from each side of the Rectangle.
   r.Inflate(-100, -100);
   this.Bounds = this.RectangleToScreen(r);

   // Make sure button2 is visible.
   this.ScrollControlIntoView(button2);
}
Private Sub ResizeForm()
   ' Enable auto-scrolling for the form.
   Me.AutoScroll = True
   
   ' Resize the form.
   Dim r As Rectangle = Me.ClientRectangle
   ' Subtract 100 pixels from each side of the Rectangle.
   r.Inflate(- 100, - 100)
   Me.Bounds = Me.RectangleToScreen(r)
   
   ' Make sure button2 is visible.
   Me.ScrollControlIntoView(button2)
End Sub

備註

AutoScroll屬性必須設定為 true ,而且至少要有一個捲軸(水準或垂直)必須可見, ScrollControlIntoView 方法才會有效果。The AutoScroll property must be set to true, and at least one of the scroll bars, horizontal or vertical, must also be visible, for the ScrollControlIntoView method to have an effect. 若要讓水準和垂直捲動條顯示出來, HScrollVScroll 屬性分別必須設定為 trueTo make the horizontal and vertical scroll bars visible, the HScroll and VScroll properties, respectively, must be set to true.

如果 activeControl 參數不是子控制項,則不會進行任何動作。If the activeControl parameter is not a child control, no action takes place.

這個方法可能會引發 Scroll 事件。This method may raise the Scroll event.

適用於

另請參閱