StatusBarDrawItemEventArgs 類別

定義

提供 DrawItem 事件的資料。

public ref class StatusBarDrawItemEventArgs : System::Windows::Forms::DrawItemEventArgs
public class StatusBarDrawItemEventArgs : System.Windows.Forms.DrawItemEventArgs
type StatusBarDrawItemEventArgs = class
    inherit DrawItemEventArgs
Public Class StatusBarDrawItemEventArgs
Inherits DrawItemEventArgs
繼承
StatusBarDrawItemEventArgs

範例

下列程式碼範例示範如何使用 Style 屬性、 StatusBarDrawItemEventHandler 委派、類別、 StatusBarPanelStyleStatusBarDrawItemEventArgs 列舉和 StatusBarDrawItemEventArgs.Panel 屬性。 若要執行範例,請將下列程式碼貼到表單中。 InitializeStatusBarPanels在表單的建構函式或 Load 方法中呼叫 方法。

StatusBar^ StatusBar1;
void InitializeStatusBarPanels()
{
   StatusBar1 = gcnew StatusBar;
   
   // Create two StatusBarPanel objects.
   StatusBarPanel^ panel1 = gcnew StatusBarPanel;
   StatusBarPanel^ panel2 = gcnew StatusBarPanel;
   
   // Set the style of the panels.  
   // panel1 will be owner-drawn.
   panel1->Style = StatusBarPanelStyle::OwnerDraw;
   
   // The panel2 object will be drawn by the operating system.
   panel2->Style = StatusBarPanelStyle::Text;
   
   // Set the text of both panels to the same date string.
   panel1->Text = System::DateTime::Today.ToShortDateString();
   panel2->Text = System::DateTime::Today.ToShortDateString();
   
   // Add both panels to the StatusBar.
   StatusBar1->Panels->Add( panel1 );
   StatusBar1->Panels->Add( panel2 );
   
   // Make panels visible by setting the ShowPanels 
   // property to True.
   StatusBar1->ShowPanels = true;
   
   // Associate the event-handling method with the DrawItem event 
   // for the owner-drawn panel.
   StatusBar1->DrawItem += gcnew StatusBarDrawItemEventHandler( this, &Form1::DrawCustomStatusBarPanel );
   this->Controls->Add( StatusBar1 );
}


// Draw the panel.
void DrawCustomStatusBarPanel( Object^ sender, StatusBarDrawItemEventArgs^ e )
{
   
   // Draw a blue background in the owner-drawn panel.
   e->Graphics->FillRectangle( Brushes::AliceBlue, e->Bounds );
   
   // Create a StringFormat object to align text in the panel.
   StringFormat^ textFormat = gcnew StringFormat;
   
   // Center the text in the middle of the line.
   textFormat->LineAlignment = StringAlignment::Center;
   
   // Align the text to the left.
   textFormat->Alignment = StringAlignment::Far;
   
   // Draw the panel's text in dark blue using the Panel 
   // and Bounds properties of the StatusBarEventArgs object 
   // and the StringFormat object.
   e->Graphics->DrawString( e->Panel->Text, StatusBar1->Font, Brushes::DarkBlue, RectangleF(e->Bounds.X,e->Bounds.Y,e->Bounds.Width,e->Bounds.Height), textFormat );
}
private StatusBar StatusBar1;

private void InitializeStatusBarPanels()
{
    StatusBar1 = new StatusBar();

    // Create two StatusBarPanel objects.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Set the style of the panels.  
    // panel1 will be owner-drawn.
    panel1.Style = StatusBarPanelStyle.OwnerDraw;

    // The panel2 object will be drawn by the operating system.
    panel2.Style = StatusBarPanelStyle.Text;

    // Set the text of both panels to the same date string.
    panel1.Text = System.DateTime.Today.ToShortDateString();
    panel2.Text = System.DateTime.Today.ToShortDateString();

    // Add both panels to the StatusBar.
    StatusBar1.Panels.Add(panel1);
    StatusBar1.Panels.Add(panel2);

    // Make panels visible by setting the ShowPanels 
    // property to True.
    StatusBar1.ShowPanels = true;

    // Associate the event-handling method with the DrawItem event 
    // for the owner-drawn panel.
    StatusBar1.DrawItem += 
        new StatusBarDrawItemEventHandler(DrawCustomStatusBarPanel);
        
    this.Controls.Add(StatusBar1);
}

// Draw the panel.
private void DrawCustomStatusBarPanel(object sender, 
    StatusBarDrawItemEventArgs e)
{

    // Draw a blue background in the owner-drawn panel.
    e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds);

    // Create a StringFormat object to align text in the panel.
    StringFormat textFormat = new StringFormat();

    // Center the text in the middle of the line.
    textFormat.LineAlignment = StringAlignment.Center;

    // Align the text to the left.
    textFormat.Alignment = StringAlignment.Far;

    // Draw the panel's text in dark blue using the Panel 
    // and Bounds properties of the StatusBarEventArgs object 
    // and the StringFormat object.
    e.Graphics.DrawString(e.Panel.Text, StatusBar1.Font, 
        Brushes.DarkBlue, new RectangleF(e.Bounds.X, 
        e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), textFormat);
}
Private StatusBar1 As StatusBar

Private Sub InitializeStatusBarPanels()
    StatusBar1 = New StatusBar

    ' Create two StatusBarPanel objects.
    Dim panel1 As New StatusBarPanel
    Dim panel2 As New StatusBarPanel

    ' Set the style of the panels.  
    ' panel1 will be owner-drawn.
    panel1.Style = StatusBarPanelStyle.OwnerDraw

    ' The panel2 object will be drawn by the operating system.
    panel2.Style = StatusBarPanelStyle.Text

    ' Set the text of both panels to the same date string.
    panel1.Text = DateTime.Today.ToShortDateString()
    panel2.Text = DateTime.Today.ToShortDateString()

    ' Add both panels to the StatusBar.
    StatusBar1.Panels.Add(panel1)
    StatusBar1.Panels.Add(panel2)

    ' Make panels visible by setting the ShowPanels 
    ' property to True.
    StatusBar1.ShowPanels = True

    ' Use the AddHandler syntax to handle the DrawItem event
    ' for the owner-drawn panel.
    AddHandler StatusBar1.DrawItem, _
        New StatusBarDrawItemEventHandler( _
        AddressOf DrawCustomStatusBarPanel)
    Me.Controls.Add(StatusBar1)
End Sub

' Draw the panel.
Private Sub DrawCustomStatusBarPanel(ByVal sender As Object, _
    ByVal e As StatusBarDrawItemEventArgs)

    ' Draw a blue background in the owner-drawn panel.
    e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds)

    ' Create a StringFormat object to align text in the panel.
    Dim textFormat As New StringFormat

    ' Center the text in the middle of the line.
    textFormat.LineAlignment = StringAlignment.Center

    ' Align the text to the left.
    textFormat.Alignment = StringAlignment.Far

    ' Draw the panel's text in dark blue using the Panel 
    ' and Bounds properties of the StatusBarEventArgs object 
    ' and the StringFormat object.
    e.Graphics.DrawString(e.Panel.Text, StatusBar1.Font, _
          Brushes.DarkBlue, New RectangleF(e.Bounds.X, e.Bounds.Y, _
          e.Bounds.Width, e.Bounds.Height), textFormat)

End Sub

備註

DrawItem 擁有者繪製 StatusBarPanel 的視覺層面變更時,就會發生此事件。 StatusBarDrawItemEventArgs指定要 Graphics 用來繪製面板的物件、 Rectangle 用來繪製面板的物件、面板識別碼、面板的狀態資訊,以及要繪製的面板。 您可以在事件的事件處理常式 DrawItem 中使用這個類別所提供的資料,在應用程式的控制項中建立自訂繪製的 StatusBar 面板。

建構函式

StatusBarDrawItemEventArgs(Graphics, Font, Rectangle, Int32, DrawItemState, StatusBarPanel)

初始化 StatusBarDrawItemEventArgs 類別的新執行個體時不指定 StatusBarPanel 的背景和前景色彩。

StatusBarDrawItemEventArgs(Graphics, Font, Rectangle, Int32, DrawItemState, StatusBarPanel, Color, Color)

使用 StatusBarDrawItemEventArgs 的指定背景和前景色彩,初始化 StatusBarPanel 類別的新執行個體。

屬性

BackColor

取得所繪製項目的背景色彩。

(繼承來源 DrawItemEventArgs)
Bounds

取得表示所繪製項目的界限的矩形。

(繼承來源 DrawItemEventArgs)
Font

取得指派給所繪製項目的字型。

(繼承來源 DrawItemEventArgs)
ForeColor

取得所繪製項目的前景色彩。

(繼承來源 DrawItemEventArgs)
Graphics

取得項目繪製其上的圖形介面。

(繼承來源 DrawItemEventArgs)
Index

取得所繪製項目的索引值。

(繼承來源 DrawItemEventArgs)
Panel

取得要繪製的 StatusBarPanel

State

取得所繪製項目的狀態。

(繼承來源 DrawItemEventArgs)

方法

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

(繼承來源 DrawItemEventArgs)
Dispose(Boolean)

提供 DrawItem 事件的資料。

(繼承來源 DrawItemEventArgs)
DrawBackground()

DrawItemEventArgs 建構函式 (Constructor) 中指定的界限內繪製背景,並使用適當的色彩。

(繼承來源 DrawItemEventArgs)
DrawFocusRectangle()

DrawItemEventArgs 建構函式中指定的界限內繪製焦點矩形 (Focus Rectangle)。

(繼承來源 DrawItemEventArgs)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱