StatusBar.OnDrawItem(StatusBarDrawItemEventArgs) メソッド

定義

OnDrawItem(StatusBarDrawItemEventArgs) イベントを発生させます。

protected:
 virtual void OnDrawItem(System::Windows::Forms::StatusBarDrawItemEventArgs ^ sbdievent);
protected virtual void OnDrawItem (System.Windows.Forms.StatusBarDrawItemEventArgs sbdievent);
abstract member OnDrawItem : System.Windows.Forms.StatusBarDrawItemEventArgs -> unit
override this.OnDrawItem : System.Windows.Forms.StatusBarDrawItemEventArgs -> unit
Protected Overridable Sub OnDrawItem (sbdievent As StatusBarDrawItemEventArgs)

パラメーター

sbdievent
StatusBarDrawItemEventArgs

イベント データを格納している StatusBarDrawItemEventArgs

次のコード例では、カスタムの背景と現在の日付を表示する所有者描画 StatusBarPanel を作成する方法を示します。 この例では、コントロールのStatusBarイベントを、DrawItemこの例で定義されているイベント ハンドラーに接続している必要があります。

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

注釈

イベントを発生させると、イベント ハンドラーがデリゲートから呼び出されます。 詳細については、処理とイベントの発生 を参照してください。

OnDrawItem メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。 派生クラスでイベントを処理する場合は、この手法をお勧めします。

注意 (継承者)

派生クラスで OnDrawItem(StatusBarDrawItemEventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnDrawItem(StatusBarDrawItemEventArgs) メソッドを呼び出してください。

適用対象

こちらもご覧ください