This documentation is archived and is not being maintained.

ScrollableControl.ScrollControlIntoView Method

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

[Visual Basic]
Public Sub ScrollControlIntoView( _
   ByVal activeControl As Control _
)
[C#]
public void ScrollControlIntoView(
 Control activeControl
);
[C++]
public: void ScrollControlIntoView(
 Control* activeControl
);
[JScript]
public function ScrollControlIntoView(
   activeControl : Control
);

Parameters

activeControl
The control to scroll into view.

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.

Example

[Visual Basic, C#, C++] The following example enables auto-scrolling for a form, resizes the form, and ensures that a button remains visible after the form is resized. This example assumes that you have a Form with a Button named button2 on it.

[Visual Basic] 
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

[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);
}

[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);
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ScrollableControl Class | ScrollableControl Members | System.Windows.Forms Namespace | AutoScroll | HScroll | VScroll

Show: