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 使 方法生效。 若要使水平滚动条和垂直滚动条可见, HScrollVScroll 属性必须分别设置为 true

activeControl如果 参数不是子控件,则不执行任何操作。

此方法可能会引发 Scroll 事件。

适用于

另请参阅