ScrollableControl.ScrollControlIntoView(Control) Method

Definition

Scrolls the specified child control into view on an auto-scroll enabled control.

C#
public void ScrollControlIntoView(System.Windows.Forms.Control activeControl);
C#
public void ScrollControlIntoView(System.Windows.Forms.Control? activeControl);

Parameters

activeControl
Control

The child control to scroll into view.

Examples

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. The example requires that you have a Form with a Button named button2 on it.

C#
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);
}

Remarks

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. To make the horizontal and vertical scroll bars visible, the HScroll and VScroll properties, respectively, must be set to true.

If the activeControl parameter is not a child control, no action takes place.

This method may raise the Scroll event.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also