Skip to main content
Bar

PopupMenu.PaintMenuBar Event

Enables you to paint the content of the bar displayed to the left of the popup menu.

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v24.2.dll

Declaration

[DXCategory("Events")]
public event BarCustomDrawEventHandler PaintMenuBar

Event Data

The PaintMenuBar event's data class is BarCustomDrawEventArgs. The following properties provide information specific to this event:

Property Description
Bounds Gets the bounding rectangle of the painted element.
Graphics Gets the drawing surface of the element being painted.
Handled Gets or sets a value specifying whether default painting must be performed.

Remarks

You can display a custom bar to the left of the popup menu. The following must be performed in order to display the bar:

  • Set the PopupMenu.MenuBarWidth property to a positive integer. This makes the bar visible.
  • Handle the PaintMenuBar event. This event allows you to paint the desired bar’s content. You can use its parameters to obtain the painting surface and the bounding rectangle of the bar. Set the BarCustomDrawEventArgs.Handled parameter to true to prohibit default painting.

Note: if the PaintMenuBar event is not handled, nothing is painted on the menu bar.

Example

The following sample code handles the PopupMenu.PaintMenuBar event. The handler fills the menu bar area with a linear gradient brush and paints “XtraBars Suite” on it.

The image below displays an example of using such a PopupMenu.PaintMenuBar event handler. (Note that the PopupMenu.MenuBarWidth property of the corresponding popup menu should be set to 20 to obtain similar output).

MenuBar - PopupMenuCustom

using System.Drawing;
using System.Drawing.Drawing2D;

readonly Font textFont = new Font("Tahoma", 11, FontStyle.Bold);
private void popupMenu1_PaintMenuBar(object sender, 
  DevExpress.XtraBars.BarCustomDrawEventArgs e) {
   // filling the background
    using(var backBrush = new LinearGradientBrush(e.Bounds, Color.Black,
        Color.Blue, LinearGradientMode.Vertical))
        e.Graphics.FillRectangle(backBrush, e.Bounds);

    // formatting the output string
    using(var outStringFormat = new StringFormat()) {
        outStringFormat.Alignment = StringAlignment.Near;
        outStringFormat.LineAlignment = StringAlignment.Center;
        outStringFormat.FormatFlags |= StringFormatFlags.DirectionVertical;

        // transforming the painting surface and modifying the bounding rectangle
        // this is needed to provide proper string orientation
        e.Graphics.RotateTransform(180);
        Rectangle rect = e.Bounds;
        rect.Offset(-rect.Width, -rect.Height);

        // painting the string
        e.Graphics.DrawString("XtraBars Suite", textFont,
            Brushes.White, rect, outStringFormat);
        e.Graphics.ResetTransform();
    }

    // prohibiting default painting
    e.Handled = true;
}
See Also