StatusBar.DrawItem 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当所有者描述的状态栏控件的可视特征发生变化时,发生此事件。
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 。 此示例要求已将 DrawItem 控件的事件 StatusBar 连接到示例中定义的事件处理程序。
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 控件中执行绘图操作。 例如,如果显示显示进度栏的所有者绘制 StatusBarPanel ,则可以使用此事件在面板上执行进度栏的绘制。 通过作为参数传递给事件处理程序的对象 StatusBarDrawItemEventArgs 提供给事件的数据,可以确定需要绘制的面板和 Graphics 用于绘制面板的 。 仅当控件中的 StatusBar 的 StatusBarPanel 属性设置为 OwnerDraw时StatusBarPanel.Style,才会引发此事件。
有关处理事件的详细信息,请参阅 处理和引发事件。