Bar

BarManager.CustomDrawItem Event

Allows you to manually paint any BarButtonItemLink within this BarManager.

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v20.1.dll

Declaration

[DXCategory("Events")]
public event BarItemCustomDrawEventHandler CustomDrawItem
<DXCategory("Events")>
Public Event CustomDrawItem As BarItemCustomDrawEventHandler

Event Data

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

Property Description
Bounds Returns this bar item link's bounds.
Cache Provides access to this bar item link's graphics cache.
DrawOnlyText Gets whether or not this bar item link should display only its caption.
DropDownBounds Gets the area occupied by the drop-down menu for this bar item link.
Glyph Gets the icon that should be displayed for this bar item link by default.
GlyphBounds Gets the area occupied by this bar item link's default icon.
Graphics Provides access to the Graphics object associated with this bar item link.
Handled Gets or sets whether or not this item link is painted manually.
LinkInfo Specifies the info for the bar item link related to this event.
RibbonItemInfo Specifies the info for the ribbon item related to this event.
ShouldDrawCheckBox Gets whether or not this bar item link should display a check box.
ShouldDrawDropDown Gets whether or not this bar item link should display its drop-down menu by default.
ShouldDrawEditor Gets whether or not this bar item link should display an editor.
State Gets the current bar item link state (normal, selected, pressed, checked, disabled etc.).
Text Gets the default text that should be displayed by this bar item link.
TextBounds Gets the area occupied by this bar item link's default text.

Remarks

The CustomDrawItem event occurs each time a bar manager needs to display an item link. This event should be used as follows.

Note that the CustomDrawItem event does not allow you to modify link properties - change its style, assign a new caption or icon. You can only use methods accessed through e.Cache and e.Graphics objects to draw lines and shapes or paint text with the specified appearance.

Example

The following code illustrates how to custom draw the last clicked item within a menu. The example suggests two possible options: use the item's default "Pressed" appearance (left screenshot) or provide custom appearance settings (right screenshot).

image

using System.Drawing;
using DevExpress.XtraBars;

namespace FlyoutExample {
    public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm {

        BarButtonItem lastClickedButton;

        public XtraForm1()
        {
            InitializeComponent();
            barManager1.CustomDrawItem += barManager1_CustomDrawItem;
            barButtonItem1.ItemClick += BarButtonItem1_ItemClick;
            barButtonItem2.ItemClick += BarButtonItem2_ItemClick;
            barButtonItem3.ItemClick += BarButtonItem3_ItemClick;
        }

        private void BarButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //...
            lastClickedButton = e.Item as BarButtonItem;
        }

        private void BarButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //...
            lastClickedButton = e.Item as BarButtonItem;
        }

        private void BarButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //...
            lastClickedButton = e.Item as BarButtonItem;
        }

        private void barManager1_CustomDrawItem(object sender, DevExpress.XtraBars.BarItemCustomDrawEventArgs e)
        {
            if (e.LinkInfo != null && e.LinkInfo.Link.Item == lastClickedButton)
            {
                //apply the default "Pressed" appearance
                e.LinkInfo.LinkState = DevExpress.XtraBars.ViewInfo.BarLinkState.Pressed;
                // or
                //custom draw last pressed buttons
                e.Cache.FillRectangle(Brushes.DarkOrange, e.Bounds);
                e.DrawArrow();
                e.DrawBorder();
                e.DrawCheckBox();
                e.DrawGlyph();
                e.DrawText();
                e.Handled = true;
            }
        }
    }
}
See Also