ScrollableControl.ScrollControlIntoView(Control) ScrollableControl.ScrollControlIntoView(Control) ScrollableControl.ScrollControlIntoView(Control) ScrollableControl.ScrollControlIntoView(Control) Method

定义

将指定的子控件滚动到支持自动滚动的控件的视图中。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 Control Control 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带有命名button2的。The 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

注解

必须将true属性设置为,并且至少有一个滚动条(水平或垂直)也必须可见, ScrollControlIntoView方法才会有效果。 AutoScrollThe 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.

适用于

另请参阅