Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Custom Draw Gallery Items

  • 2 minutes to read
In This Article

#Example 1

In this example the BaseGallery.CustomDrawItemText event is handled to manually paint the text within Gallery items.

The full source code can be found in the ‘Ribbon Simple Pad’ demo supplied with the XtraBars.

The image below shows the result:

CustomDrawItemText

using DevExpress.XtraBars.Ribbon.ViewInfo;

private void gddFont_Gallery_CustomDrawItemText(object sender, GalleryItemCustomDrawEventArgs e) {
    DevExpress.XtraBars.Ribbon.ViewInfo.GalleryItemViewInfo itemInfo = e.ItemInfo as DevExpress.XtraBars.Ribbon.ViewInfo.GalleryItemViewInfo;
    itemInfo.PaintAppearance.ItemDescriptionAppearance.Normal.DrawString(e.Cache, e.Item.Description, itemInfo.DescriptionBounds);
    AppearanceObject app = itemInfo.PaintAppearance.ItemCaptionAppearance.Normal.Clone() as AppearanceObject;
    app.Font = (Font)e.Item.Tag;
    try {
        e.Cache.DrawString(e.Item.Caption, app.Font, app.GetForeBrush(e.Cache), itemInfo.CaptionBounds);
    }
    catch { }
    e.Handled = true;
}

#Example 2

In this example the BaseGallery.CustomDrawItemImage event is handled to manually paint item images within the Font Color Gallery. Individual items correspond to specific colors.

The full source code can be found in the ‘Ribbon Simple Pad’ demo supplied with the XtraBars.

The image below shows the result:

Gallery_CustomDrawItemImage

private void gddFontColor_Gallery_CustomDrawItemImage(object sender, 
  GalleryItemCustomDrawEventArgs e) {
    Color clr = (Color)e.Item.Tag;
    using(Brush brush = new SolidBrush(clr)) {
        e.Cache.FillRectangle(brush, e.Bounds);
        e.Handled = true;
    }
}