StatusBarPanel.AutoSize 属性

获取或设置一个值,该值指示是否自动调整状态栏面板的大小。

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

语法

声明
Public Property AutoSize As StatusBarPanelAutoSize
用法
Dim instance As StatusBarPanel
Dim value As StatusBarPanelAutoSize

value = instance.AutoSize

instance.AutoSize = value
public StatusBarPanelAutoSize AutoSize { get; set; }
public:
property StatusBarPanelAutoSize AutoSize {
    StatusBarPanelAutoSize get ();
    void set (StatusBarPanelAutoSize value);
}
/** @property */
public StatusBarPanelAutoSize get_AutoSize ()

/** @property */
public void set_AutoSize (StatusBarPanelAutoSize value)
public function get AutoSize () : StatusBarPanelAutoSize

public function set AutoSize (value : StatusBarPanelAutoSize)

属性值

StatusBarPanelAutoSize 值之一。默认为 None

异常

异常类型 条件

InvalidEnumArgumentException

分配给该属性的值不是 StatusBarPanelAutoSize 枚举的成员。

备注

设置成 ContentsStatusBarPanel 对象优先于那些设置成 Spring 值的面板。例如,如果 StatusBarPanelAutoSize 属性设置为 Spring,而 StatusBarPanelAutoSize 属性设置为 Contents,则前者会根据后者所需的空间缩短。

可以使用 AutoSize 来确保 StatusBarPanel 的内容在包含多个面板的 StatusBar 控件中正确显示。例如,一个包含文本的面板可能需要自动调整大小,以适合它所显示的文本量 (Contents),而 StatusBar 上显示所有者描述的进度栏的另一个面板必须是大小固定的 (None)。

示例

下面的代码示例在窗体上创建一个 StatusBar 控件,并添加两个 StatusBarPanel 对象。第一个 StatusBarPanel 名为 panel1,它显示应用程序的状态文本。另一个 StatusBarPanel 名为 panel2,它显示当前日期,并使用 StatusBarPanel 类的 ToolTipText 属性显示当前时间。此示例使用 ShowPanels 属性确保显示多个面板而不是一个标准面板,并使用 Panels 属性访问 StatusBar.StatusBarPanelCollectionAdd 方法,以向 StatusBar 中添加面板。该示例还使用 AutoSizeBorderStyleToolTipTextText 属性来初始化 StatusBarPanel 对象。本示例假定示例中定义的方法已定义并且是从 Form 的构造函数中调用的。

Private Sub CreateMyStatusBar()
   ' Create a StatusBar control.
   Dim statusBar1 As New StatusBar()

   ' Create two StatusBarPanel objects to display in the StatusBar.
   Dim panel1 As New StatusBarPanel()
   Dim panel2 As New StatusBarPanel()

   ' Display the first panel with a sunken border style.
   panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken

   ' Initialize the text of the panel.
   panel1.Text = "Ready..."

   ' Set the AutoSize property to use all remaining space on the StatusBar.
   panel1.AutoSize = StatusBarPanelAutoSize.Spring
   
   ' Display the second panel with a raised border style.
   panel2.BorderStyle = StatusBarPanelBorderStyle.Raised
   
   ' Create ToolTip text that displays the time the application was started.
   panel2.ToolTipText = "Started: " & System.DateTime.Now.ToShortTimeString()

   ' Set the text of the panel to the current date.
   panel2.Text = System.DateTime.Today.ToLongDateString()

   ' Set the AutoSize property to size the panel to the size of the contents.
   panel2.AutoSize = StatusBarPanelAutoSize.Contents

   ' Display panels in the StatusBar control.
   statusBar1.ShowPanels = True

   ' Add both panels to the StatusBarPanelCollection of the StatusBar.            
   statusBar1.Panels.Add(panel1)
   statusBar1.Panels.Add(panel2)

   ' Add the StatusBar to the form.
   Me.Controls.Add(statusBar1)
End Sub
private void CreateMyStatusBar()
{
    // Create a StatusBar control.
    StatusBar statusBar1 = new StatusBar();
    // Create two StatusBarPanel objects to display in the StatusBar.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Display the first panel with a sunken border style.
    panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;
    // Initialize the text of the panel.
    panel1.Text = "Ready...";
    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.AutoSize = StatusBarPanelAutoSize.Spring;
    
    // Display the second panel with a raised border style.
    panel2.BorderStyle = StatusBarPanelBorderStyle.Raised;
    
    // Create ToolTip text that displays time the application was 
          //started.
    panel2.ToolTipText = "Started: " + System.DateTime.Now.ToShortTimeString();
    // Set the text of the panel to the current date.
    panel2.Text = System.DateTime.Today.ToLongDateString();
    // Set the AutoSize property to size the panel to the size of the contents.
    panel2.AutoSize = StatusBarPanelAutoSize.Contents;
                
    // Display panels in the StatusBar control.
    statusBar1.ShowPanels = true;

    // Add both panels to the StatusBarPanelCollection of the StatusBar.            
    statusBar1.Panels.Add(panel1);
    statusBar1.Panels.Add(panel2);

    // Add the StatusBar to the form.
    this.Controls.Add(statusBar1);
}
private:
   void CreateMyStatusBar()
   {
      // Create a StatusBar control.
      StatusBar^ statusBar1 = gcnew StatusBar;

      // Create two StatusBarPanel objects to display in the StatusBar.
      StatusBarPanel^ panel1 = gcnew StatusBarPanel;
      StatusBarPanel^ panel2 = gcnew StatusBarPanel;

      // Display the first panel with a sunken border style.
      panel1->BorderStyle = StatusBarPanelBorderStyle::Sunken;

      // Initialize the text of the panel.
      panel1->Text = "Ready...";

      // Set the AutoSize property to use all remaining space on the StatusBar.
      panel1->AutoSize = StatusBarPanelAutoSize::Spring;

      // Display the second panel with a raised border style.
      panel2->BorderStyle = StatusBarPanelBorderStyle::Raised;

      // Create ToolTip text that displays the time the application
      // was started.
      panel2->ToolTipText = System::DateTime::Now.ToShortTimeString();

      // Set the text of the panel to the current date.
      panel2->Text = "Started: " + System::DateTime::Today.ToLongDateString();

      // Set the AutoSize property to size the panel to the size of the contents.
      panel2->AutoSize = StatusBarPanelAutoSize::Contents;

      // Display panels in the StatusBar control.
      statusBar1->ShowPanels = true;

      // Add both panels to the StatusBarPanelCollection of the StatusBar.   
      statusBar1->Panels->Add( panel1 );
      statusBar1->Panels->Add( panel2 );

      // Add the StatusBar to the form.
      this->Controls->Add( statusBar1 );
   }
private void CreateMyStatusBar()
{
    // Create a StatusBar control.
    StatusBar statusBar1 = new StatusBar();

    // Create two StatusBarPanel objects to display in the StatusBar.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Display the first panel with a sunken border style.
    panel1.set_BorderStyle(StatusBarPanelBorderStyle.Sunken);

    // Initialize the text of the panel.
    panel1.set_Text("Ready...");

    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.set_AutoSize(StatusBarPanelAutoSize.Spring);

    // Display the second panel with a raised border style.
    panel2.set_BorderStyle(StatusBarPanelBorderStyle.Raised);

    // Create ToolTip text that displays the time the application was started.
    panel2.set_ToolTipText("Started: " + System.DateTime.get_Now().ToShortTimeString());
    
// Set the text of the panel to the current date.
    panel2.set_Text(System.DateTime.get_Today().ToLongDateString());
    
// Set the AutoSize property to size the panel to the size of the 
    // contents.
    panel2.set_AutoSize(StatusBarPanelAutoSize.Contents);
    // Display panels in the StatusBar control.
    statusBar1.set_ShowPanels(true);
    // Add both panels to the StatusBarPanelCollection of the StatusBar.    
    statusBar1.get_Panels().Add(panel1);
    statusBar1.get_Panels().Add(panel2);
    // Add the StatusBar to the form.
    this.get_Controls().Add(statusBar1);
} //CreateMyStatusBar

平台

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

请参见

参考

StatusBarPanel 类
StatusBarPanel 成员
System.Windows.Forms 命名空间
StatusBarPanelAutoSize