StatusBarPanel.AutoSize 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出狀態列面板是否會自動調整大小。
public:
property System::Windows::Forms::StatusBarPanelAutoSize AutoSize { System::Windows::Forms::StatusBarPanelAutoSize get(); void set(System::Windows::Forms::StatusBarPanelAutoSize value); };
public System.Windows.Forms.StatusBarPanelAutoSize AutoSize { get; set; }
member this.AutoSize : System.Windows.Forms.StatusBarPanelAutoSize with get, set
Public Property AutoSize As StatusBarPanelAutoSize
屬性值
其中一個 StatusBarPanelAutoSize 值。 預設值為 None。
例外狀況
指派給屬性的值不是 StatusBarPanelAutoSize 列舉的成員。
範例
下列程式碼範例會在表單上建立 控制項,並新增兩 StatusBarPanel 個 StatusBar 物件。 名為 的第一個 StatusBarPanelpanel1
會顯示應用程式的狀態文字。 第二 StatusBarPanel 個名為 panel2
的 會顯示目前的日期,並使用 ToolTipText 類別的 StatusBarPanel 屬性來顯示目前的時間。 此範例會 ShowPanels 使用 屬性來確保顯示面板,而不是標準面板,並使用 Panels 屬性來存取 Add 的 方法 StatusBar.StatusBarPanelCollection ,將面板新增至 StatusBar 。 此範例也會使用 AutoSize 、 BorderStyleToolTipText 和 Text 屬性來初始化 StatusBarPanel 物件。 這個範例假設範例中定義的 方法是由 的建構函式所定義,並從 的 Form 建構函式呼叫。
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.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 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
備註
StatusBarPanel 物件設定為 Contents 的優先順序高於設定為 Spring 值的面板。 例如, StatusBarPanelAutoSize 如果 StatusBarPanelAutoSize 屬性設定為 的 ,其 屬性設定 Spring 為 ,則會縮短該 Contents 空間。
您可以使用 AutoSize 確保 的內容 StatusBarPanel 正確顯示在包含多個面板的控制項中 StatusBar 。 例如,您可能會想要包含文字的面板自動調整為它所顯示的文字量 () Contents ,而另一個面板在顯示擁有者繪製進度列的 StatusBar 上,則需要固定大小 (None) 。