StatusBar.DrawItem StatusBar.DrawItem StatusBar.DrawItem StatusBar.DrawItem Event

定義

オーナー描画ステータス バー コントロールの視覚的要素が変更された場合に発生します。Occurs when a visual aspect of an owner-drawn status bar control changes.

public:
 event System::Windows::Forms::StatusBarDrawItemEventHandler ^ DrawItem;
public event System.Windows.Forms.StatusBarDrawItemEventHandler DrawItem;
member this.DrawItem : System.Windows.Forms.StatusBarDrawItemEventHandler 
Public Custom Event DrawItem As StatusBarDrawItemEventHandler 

次のコード例は、カスタムの背景と現在のStatusBarPanel日付を表示するオーナー描画を作成する方法を示しています。The following code example demonstrates how to create an owner-drawn StatusBarPanel that displays a custom background and the current date. この例では、 DrawItem StatusBarコントロールのイベントを、例で定義されているイベントハンドラーに接続している必要があります。This example requires that you have connected the DrawItem event of a StatusBar control to the event handler defined in the example.

private:
   void DrawMyPanel( Object^ /*sender*/, System::Windows::Forms::StatusBarDrawItemEventArgs^ sbdevent )
   {
      // Create a StringFormat object to align text in the panel.
      StringFormat^ sf = gcnew StringFormat;

      // Format the String of the StatusBarPanel to be centered.
      sf->Alignment = StringAlignment::Center;
      sf->LineAlignment = StringAlignment::Center;

      // Draw a back blackground in owner-drawn panel.
      sbdevent->Graphics->FillRectangle( Brushes::Black, sbdevent->Bounds );

      // Draw the current date (short date format) with white text in the control's font.
      sbdevent->Graphics->DrawString( DateTime::Today.ToShortDateString(), statusBar1->Font, Brushes::White, sbdevent->Bounds, sf );
   }
private void DrawMyPanel(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
{
   // Create a StringFormat object to align text in the panel.
   StringFormat sf = new StringFormat();
   // Format the String of the StatusBarPanel to be centered.
   sf.Alignment = StringAlignment.Center;
   sf.LineAlignment = StringAlignment.Center;

   // Draw a black background in owner-drawn panel.
   sbdevent.Graphics.FillRectangle(Brushes.Black, sbdevent.Bounds);
   // Draw the current date (short date format) with white text in the control's font.
   sbdevent.Graphics.DrawString(DateTime.Today.ToShortDateString(), 
      statusBar1.Font,Brushes.White,sbdevent.Bounds,sf);
}
Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem

   ' Create a StringFormat object to align text in the panel.
   Dim sf As New StringFormat()
   ' Format the String of the StatusBarPanel to be centered.
   sf.Alignment = StringAlignment.Center
   sf.LineAlignment = StringAlignment.Center

   ' Draw a black background in owner-drawn panel.
   sbdevent.Graphics.FillRectangle(Brushes.Black, sbdevent.Bounds)
   ' Draw the current date (short date format) with white text in the control's font.
   sbdevent.Graphics.DrawString(DateTime.Today.ToShortDateString(), StatusBar1.Font, Brushes.White, _
         New RectangleF(sbdevent.Bounds.X, sbdevent.Bounds.Y, _
         sbdevent.Bounds.Width, sbdevent.Bounds.Height), sf)
End Sub

注釈

このイベントを使用すると、オーナー描画StatusBarコントロールで描画操作を実行できます。You can use this event to perform drawing operations in an owner-drawn StatusBar control. たとえば、進行状況バーを表示するオーナー描画StatusBarPanelを表示する場合は、このイベントを使用して、パネル上の進行状況バーの描画を実行できます。For example, if you display an owner-drawn StatusBarPanel that displays a progress bar, you can use this event to perform the drawing of the progress bar on the panel. イベントハンドラーにパラメーターとして渡さStatusBarDrawItemEventArgsれたオブジェクトを介してイベントに提供されるデータは、描画する必要があるパネルと、 Graphicsパネルに描画するために使用するを決定することができます。The data provided to the event through the StatusBarDrawItemEventArgs object passed as a parameter to the event handler enables you to determine the panel that needs to be drawn and the Graphics to use to draw to the panel. StatusBarPanel.Styleこのイベントは、 StatusBarPanel StatusBarコントロール内ののプロパティがにOwnerDraw設定されている場合にのみ発生します。This event is only raised when the StatusBarPanel.Style property of a StatusBarPanel in a StatusBar control is set to OwnerDraw.

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。For more information about handling events, see Handling and Raising Events.

適用対象

こちらもご覧ください