Back to Devexpress

BaseGallery.CustomDrawItemImage Event

windowsforms-devexpress-dot-xtrabars-dot-ribbon-dot-gallery-dot-basegallery-528c98f9.md

latest5.5 KB
Original Source

BaseGallery.CustomDrawItemImage Event

Enables the Gallery item’s image 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 CustomDrawItemImage
vb
<DXCategory("Events")>
Public Event CustomDrawItemImage As GalleryItemCustomDrawEventHandler

Event Data

The CustomDrawItemImage 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 CustomDrawItemImage event is raised each time an item’s image is about to be painted. The event parameter provides all the information necessary to paint an image. Set the Handled property to true to prohibit default image painting.

Example

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:

csharp
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;
    }
}
vb
Private Sub gddFontColor_Gallery_CustomDrawItemImage(ByVal sender As Object, _
  ByVal e As GalleryItemCustomDrawEventArgs) _
  Handles gddFontColor.GalleryCustomDrawItemImage, _
  rgbiFontColor.GalleryCustomDrawItemImage
    Dim clr As Color = CType(e.Item.Tag, Color)
    Dim brush As brush = New SolidBrush(clr)
    Try
        e.Cache.FillRectangle(brush, e.Bounds)
        e.Handled = True
    Finally
        CType(brush, IDisposable).Dispose()
    End Try
End Sub

See Also

CustomDrawItemText

BaseGallery Class

BaseGallery Members

DevExpress.XtraBars.Ribbon.Gallery Namespace