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,其中包含一个名为 button2ButtonThe 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.

适用于

另请参阅