Form.AutoScroll 属性

定义

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

public:
 virtual property bool AutoScroll { bool get(); void set(bool value); };
public override bool AutoScroll { get; set; }
member this.AutoScroll : bool with get, set
Public Overrides Property AutoScroll As Boolean

属性值

Boolean

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

示例

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

private:
   void DisplayMyScrollableForm()
   {
      // Create a new form.
      Form^ form2 = gcnew Form;

      // Create a button to add to the new form.
      Button^ button1 = gcnew Button;

      // Set text for the button.
      button1->Text = "Scrolled Button";

      // Set the size of the button.
      button1->Size = System::Drawing::Size( 100, 30 );

      // Set the location of the button to be outside the form's client area.
      button1->Location = 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();
   }
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();
}
Private Sub DisplayMyScrollableForm()
   ' Create a new form.
   Dim form2 As New Form()
   ' Create a button to add to the new form.
   Dim button1 As 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()
End Sub

注解

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

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

适用于