Form.AutoScroll Form.AutoScroll Form.AutoScroll Form.AutoScroll Property

定义

获取或设置一个值,该值指示窗体是否启用自动滚动。Gets or sets a value indicating whether the form enables autoscrolling.

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

属性值

若要在窗体上启用自动滚动,为 true;否则,为 falsetrue to enable autoscrolling on the form; otherwise, false. 默认值为 falseThe default is false.

示例

下面的示例演示如何使用AutoScroll属性来启用对窗体的工作区外部的控件的显示。The following example demonstrates how to use the AutoScroll property to enable the display of controls that are outsize the client area of a form. 该示例创建一个新窗体,并Button向窗体添加一个控件。The example creates a new form and adds a Button control to the form. Button控件定位在新窗体的客户端区域外部。The Button control is positioned outsize the client area of the new form. AutoScroll属性设置为 true 可在窗体上显示滚动条,以允许用户滚动到控件。The AutoScroll property is set to true to display scroll bars on the form to enable the user to scroll to the control. 此示例要求在此示例中定义的方法从事件处理程序中的另一个窗体或其他方法中调用。This example requires that the method defined in this example is called from another form in an event handler or other method.

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,则在窗体上的任何控件位于窗体的工作区之外时,滚动条将显示在窗体上。If this property is set to true, scroll bars are displayed on the form if any controls are located outside the form's client region. 此外,当自动滚动为 on 时,窗体的工作区会自动滚动以使控件具有输入焦点。Additionally, when autoscrolling is on, the client area of the form automatically scrolls to make the control with input focus visible.

您可以使用此属性来防止用户在其视频分辨率设置设置为低分辨率时无法查看控件。You can use this property to prevent users from losing the ability to view controls when their video resolution settings are set to a low resolution.

适用于