StatusBar.DrawItem イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As StatusBar Dim handler As StatusBarDrawItemEventHandler AddHandler instance.DrawItem, handler
public: event StatusBarDrawItemEventHandler^ DrawItem { void add (StatusBarDrawItemEventHandler^ value); void remove (StatusBarDrawItemEventHandler^ value); }

このイベントを使用すると、オーナー描画 StatusBar コントロールで描画操作を実行できます。たとえば、プログレス バーを表示するオーナー描画 StatusBarPanel を表示する場合は、このイベントを使用してパネル上にプログレス バーの描画を実行できます。パラメータとしてイベント ハンドラに渡された StatusBarDrawItemEventArgs オブジェクトを通じてイベントに提供されたデータを使用すると、描画する必要があるパネルとパネルを描画するために使用する Graphics を確認できます。このイベントは、StatusBar コントロール内の StatusBarPanel の StatusBarPanel.Style プロパティが OwnerDraw に設定されている場合にだけ発生します。

カスタム背景と現在の日付を表示するオーナー描画 StatusBarPanel を作成する方法を次のコード例に示します。この例は、StatusBar コントロールの DrawItem イベントが、この例で定義されているイベント ハンドラに接続されていることを前提にしています。
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
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: 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.set_Alignment(StringAlignment.Center); sf.set_LineAlignment(StringAlignment.Center); // Draw a back blackground in owner-drawn panel. sbdEvent.get_Graphics().FillRectangle(Brushes.get_Black(), sbdEvent.get_Bounds()); // Draw the current date (short date format) with white text // in the control's font. sbdEvent.get_Graphics().DrawString(DateTime.get_Today(). ToShortDateString(), statusBar1.get_Font(), Brushes.get_White(), RectangleF.op_Implicit(sbdEvent.get_Bounds()), sf); } //DrawMyPanel

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- StatusBar.DrawItem イベントのページへのリンク