Back to Devexpress

PopupMenu.MenuBarWidth Property

windowsforms-devexpress-dot-xtrabars-dot-popupmenu-3cd6df4c.md

latest5.3 KB
Original Source

PopupMenu.MenuBarWidth Property

Gets or sets the width of the bar displayed to the left of the popup menu’s content.

Namespace : DevExpress.XtraBars

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(0)]
[DXCategory("Appearance")]
public virtual int MenuBarWidth { get; set; }
vb
<DefaultValue(0)>
<DXCategory("Appearance")>
Public Overridable Property MenuBarWidth As Integer

Property Value

TypeDefaultDescription
Int320

An integer value specifying the width of the menu bar in pixels.

|

Remarks

If the MenuBarWidth property value is 0 , the menu bar is not displayed. Change this property value to display the bar. The image below displays the default appearance of a popup menu when the MenuBarWidth property is set to 20.

Nothing is painted in the menu bar by default. You must handle the PopupMenu.PaintMenuBar event to paint the menu bar’s contents. This event provides parameters that allow you to obtain the painting surface and the bounding rectangle of the 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).

csharp
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;
}
vb
Imports System.Drawing
Imports System.Drawing.Drawing2D

Private ReadOnly textFont As New Font("Tahoma", 11, FontStyle.Bold)
Private Sub PopupMenu1_PaintMenuBar(ByVal sender As Object, _
  ByVal e As DevExpress.XtraBars.BarCustomDrawEventArgs) Handles PopupMenu1.PaintMenuBar
    ' filling the background
    Using backBrush = New LinearGradientBrush(e.Bounds, Color.Black, Color.Blue, LinearGradientMode.Vertical)
        e.Graphics.FillRectangle(backBrush, e.Bounds)
    End Using

    ' formatting the output string
    Using outStringFormat = New StringFormat()
        outStringFormat.Alignment = StringAlignment.Near
        outStringFormat.LineAlignment = StringAlignment.Center
        outStringFormat.FormatFlags = outStringFormat.FormatFlags Or StringFormatFlags.DirectionVertical

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

        ' painting the string
        e.Graphics.DrawString("XtraBars Suite", textFont, Brushes.White, rect, outStringFormat)
        e.Graphics.ResetTransform()
    End Using

    ' prohibiting default painting
    e.Handled = True
End Sub

See Also

PopupMenu.PaintMenuBar

MenuBarWidth

BarCustomContainerItem.PaintMenuBar

PopupMenu Class

PopupMenu Members

DevExpress.XtraBars Namespace