ScrollableControl.AutoScroll 属性

获取或设置一个值,该值指示容器是否允许用户滚动到任何放置在其可见边界之外的控件。

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

语法

声明
<LocalizableAttribute(True)> _
Public Overridable Property AutoScroll As Boolean
用法
Dim instance As ScrollableControl
Dim value As Boolean

value = instance.AutoScroll

instance.AutoScroll = value
[LocalizableAttribute(true)] 
public virtual bool AutoScroll { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property bool AutoScroll {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_AutoScroll ()

/** @property */
public void set_AutoScroll (boolean value)
public function get AutoScroll () : boolean

public function set AutoScroll (value : boolean)

属性值

如果容器允许自动滚动,则为 true;否则为 false。默认值为 false

备注

true 时,此属性允许容器有一个大于其可见边界的虚拟大小。

示例

下面的代码示例使用派生类 Panel。该示例计算文本框的位置并更改其父容器(面板控件)的外观和行为。编写该示例时,假定已创建了 Panel 控件、TextBoxButton 的实例。将文本框放在面板上,以便它至少与面板的一条边缘重叠。单击一个按钮调用此子过程可查看面板行为和外观上的差异。

Private Sub SetAutoScrollMargins()
    ' If the text box is outside the panel's bounds,
    ' turn on auto-scrolling and set the margin. 
    If (text1.Location.X > panel1.Location.X) Or _
        (text1.Location.Y > panel1.Location.Y) Then
        panel1.AutoScroll = True
        ' If the AutoScrollMargin is set to less
        ' than (5,5), set it to 5,5. 
        If (panel1.AutoScrollMargin.Width < 5) Or _
            (panel1.AutoScrollMargin.Height < 5) Then
            
            panel1.SetAutoScrollMargin(5, 5)
        End If
    End If
End Sub
private void SetAutoScrollMargins()
 {
    /* If the text box is outside the panel's bounds, 
       turn on auto-scrolling and set the margin. */  
    if (text1.Location.X > panel1.Location.X || 
       text1.Location.Y > panel1.Location.Y)
    {
       panel1.AutoScroll = true;
       /* If the AutoScrollMargin is set to less 
          than (5,5), set it to 5,5. */
       if( panel1.AutoScrollMargin.Width < 5 || 
          panel1.AutoScrollMargin.Height < 5)
       {
          panel1.SetAutoScrollMargin(5, 5);
       }
    }
 }
 
void SetAutoScrollMargins()
{
   /* If the text box is outside the panel's bounds, 
          turn on auto-scrolling and set the margin. */
   if ( text1->Location.X > panel1->Location.X || text1->Location.Y > panel1->Location.Y )
   {
      panel1->AutoScroll = true;

      /* If the AutoScrollMargin is set to less 
                than (5,5), set it to 5,5. */
      if ( panel1->AutoScrollMargin.Width < 5 || panel1->AutoScrollMargin.Height < 5 )
      {
         panel1->SetAutoScrollMargin( 5, 5 );
      }
   }
}
private void SetAutoScrollMargins()
{
    /* If the text box is outside the panel's bounds, 
       turn on auto-scrolling and set the margin. */
    if (text1.get_Location().get_X() > panel1.get_Location().get_X() 
        || text1.get_Location().get_Y() > panel1.get_Location().get_Y()) {
        
        panel1.set_AutoScroll(true);

        /* If the AutoScrollMargin is set to less 
           than (5,5), set it to 5,5. */
        if (panel1.get_AutoScrollMargin().get_Width() < 5 
            || panel1.get_AutoScrollMargin().get_Height() < 5) {
                panel1.SetAutoScrollMargin(5, 5);
        }
    }
} //SetAutoScrollMargins

平台

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

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

ScrollableControl 类
ScrollableControl 成员
System.Windows.Forms 命名空间
GetScrollState
SetScrollState
AutoScrollMargin
AutoScrollPosition
VerticalScroll
HorizontalScroll
AdjustFormScrollbars
ScrollToControl