Form.AutoScroll 属性

定义

获取或设置一个值,该值指示窗体是否启用自动滚动。

C#
public override bool AutoScroll { get; set; }

属性值

Boolean

若要在窗体上启用自动滚动,为 true;否则,为 false。 默认值为 false

示例

下面的示例演示如何使用 AutoScroll 该属性启用窗体的工作区的控件的显示。 该示例创建一个新窗体,并将控件 Button 添加到窗体。 控件 Button 将定位到新窗体的工作区外。 该 AutoScroll 属性设置为 true 以在窗体上显示滚动条,使用户能够滚动到控件。 此示例要求从事件处理程序或其他方法中的另一个窗体调用此示例中定义的方法。

C#
private void DisplayMyScrollableForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Create a button to add to the new form.
   Button button1 = new Button();
   // Set text for the button.
   button1.Text = "Scrolled Button";
   // Set the size of the button.
   button1.Size = new Size(100,30);
   // Set the location of the button to be outside the form's client area.
   button1.Location = new Point(form2.Size.Width + 200, form2.Size.Height + 200);

   // Add the button control to the new form.
   form2.Controls.Add(button1);
   // Set the AutoScroll property to true to provide scrollbars.
   form2.AutoScroll = true;

   // Display the new form as a dialog box.
   form2.ShowDialog();
}

注解

如果此属性设置为 true,则滚动条将显示在窗体上(如果任何控件位于窗体的客户端区域之外)。 此外,当自动注册处于打开状态时,窗体的工作区会自动滚动,以使具有输入焦点的控件可见。

可以使用此属性防止用户在视频分辨率设置设置为低分辨率时失去查看控件的能力。

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7