ScrollableControl.ScrollControlIntoView 方法

将指定的子控件滚动到支持自动滚动的控件的视图中。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub ScrollControlIntoView ( _
    activeControl As Control _
)
用法
Dim instance As ScrollableControl
Dim activeControl As Control

instance.ScrollControlIntoView(activeControl)
public void ScrollControlIntoView (
    Control activeControl
)
public:
void ScrollControlIntoView (
    Control^ activeControl
)
public void ScrollControlIntoView (
    Control activeControl
)
public function ScrollControlIntoView (
    activeControl : Control
)

参数

  • activeControl
    要滚动到视图中的子控件。

备注

必须将 AutoScroll 属性设置为 true,并且至少一个(水平或垂直)滚动条也必须是可见的,ScrollControlIntoView 方法才有效。要使水平滚动条和垂直滚动条可见,必须分别将 HScrollVScroll 属性设置为 true

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

此方法可能引发 Scroll 事件。

示例

下面的代码示例启用窗体的自动滚动,调整窗体的大小并确保调整了窗体的大小后按钮仍然可见。本示例要求有一个含有 Button(名为 button2)的 Form

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
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 void ResizeForm()
{
    // Enable auto-scrolling for the form.
    this.set_AutoScroll(true);
    // Resize the form.
    Rectangle r = this.get_ClientRectangle();
    // Subtract 100 pixels from each side of the Rectangle.
    r.Inflate(-100, -100);
    this.set_Bounds(this.RectangleToScreen(r));
    // Make sure button2 is visible.
    this.ScrollControlIntoView(button2);
} //ResizeForm

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ScrollableControl 类
ScrollableControl 成员
System.Windows.Forms 命名空间
AutoScroll
SetDisplayRectLocation
HScroll
VScroll
Scroll