Back to Devexpress

BaseGallery.CustomDrawItemText Event

windowsforms-devexpress-dot-xtrabars-dot-ribbon-dot-gallery-dot-basegallery-21bbdb06.md

latest7.7 KB
Original Source

BaseGallery.CustomDrawItemText Event

Enables the Gallery item’s text to be painted manually.

Namespace : DevExpress.XtraBars.Ribbon.Gallery

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event GalleryItemCustomDrawEventHandler CustomDrawItemText
vb
<DXCategory("Events")>
Public Event CustomDrawItemText As GalleryItemCustomDrawEventHandler

Event Data

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

PropertyDescription
BoundsGets the bounding rectangle of the Gallery item currently being painted.
CacheGets an object which specifies the storage for the most used pens, fonts and brushes.
GalleryGets the Gallery that contains the processed Gallery item. Inherited from GalleryItemEventArgs.
HandledGets or sets whether an event was handled. If it was handled default painting isn’t required.
InRibbonGalleryLinkFor In-Ribbon galleries, gets the bar item link that displays the current gallery. Inherited from GalleryItemEventArgs.
ItemGets the Gallery item currently being processed. Inherited from GalleryItemEventArgs.
ItemInfoGets the information which is required to paint a Gallery item.

The event data class exposes the following methods:

MethodDescription
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event.

Remarks

The CustomDrawItemText event is raised each time an item’s text is about to be painted. The event parameter provides all the information necessary to paint the text. Set the Handled property to true to prohibit default text painting.

Example

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:

csharp
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;
}
vb
Imports DevExpress.XtraBars.Ribbon.ViewInfo

Private Sub gddFont_Gallery_CustomDrawItemText(ByVal sender As Object, ByVal e As GalleryItemCustomDrawEventArgs) Handles gddFont.GalleryCustomDrawItemText
    Dim itemInfo As DevExpress.XtraBars.Ribbon.ViewInfo.GalleryItemViewInfo = TryCast(e.ItemInfo, DevExpress.XtraBars.Ribbon.ViewInfo.GalleryItemViewInfo)
    itemInfo.PaintAppearance.ItemDescriptionAppearance.Normal.DrawString(e.Cache, e.Item.Description, itemInfo.DescriptionBounds)
    Dim app As AppearanceObject = TryCast(itemInfo.PaintAppearance.ItemCaptionAppearance.Normal.Clone(), AppearanceObject)
    app.Font = CType(e.Item.Tag, Font)
    Try
        e.Cache.DrawString(e.Item.Caption, app.Font, app.GetForeBrush(e.Cache), itemInfo.CaptionBounds)
    Catch
    End Try
    e.Handled = True
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawItemText event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-gallerycontrol-drag-drop-items/CS/DragDropExample/DragDropHelper.cs#L42

csharp
galleryControl2.DragDrop += OnGalleryControlDragDrop;
galleryControl1.Gallery.CustomDrawItemText += OnCustomDrawItemText;
galleryControl2.Gallery.CustomDrawItemText += OnCustomDrawItemText;

winforms-gallerycontrol-drag-drop-items/VB/DragDropExample/DragDropHelper.vb#L43

vb
AddHandler galleryControl2.DragDrop, AddressOf OnGalleryControlDragDrop
AddHandler galleryControl1.Gallery.CustomDrawItemText, AddressOf OnCustomDrawItemText
AddHandler galleryControl2.Gallery.CustomDrawItemText, AddressOf OnCustomDrawItemText

See Also

CustomDrawItemImage

BaseGallery Class

BaseGallery Members

DevExpress.XtraBars.Ribbon.Gallery Namespace