共用方式為


ScrollableControl.ScrollControlIntoView(Control) 方法

定義

將指定的子控制項捲動至已啟用自動捲動之控制項的檢視中。

public:
 void ScrollControlIntoView(System::Windows::Forms::Control ^ activeControl);
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

要捲動至檢視中的子控制項。

範例

下列程式碼範例會啟用表單的自動捲動、調整表單大小,並確保表單調整大小之後,按鈕仍保持可見狀態。 此範例會要求您在上具有 Form 具名 button2Button

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 其中一個捲軸水準或垂直,方法才能生效。 若要讓水準和垂直捲動條可見, HScroll 必須分別將 和 VScroll 屬性設定為 true

activeControl如果參數不是子控制項,則不會採取任何動作。

這個方法可能會引發 Scroll 事件。

適用於

另請參閱