Back to Devexpress

SpreadsheetControl.CustomDrawCommentIndicator Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-8b4f0638.md

latest6.5 KB
Original Source

SpreadsheetControl.CustomDrawCommentIndicator Event

Allows you to customize comment indicators.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public event CustomDrawCommentIndicatorEventHandler CustomDrawCommentIndicator
vb
Public Event CustomDrawCommentIndicator As CustomDrawCommentIndicatorEventHandler

Event Data

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

PropertyDescription
CacheGets an object that serves as the storage for pens, fonts and brushes. Inherited from CustomDrawObjectEventsArgs.
CellGets a cell that contains a comment indicator being pained.
CellBoundsReturns the cell’s boundaries, excluding cell borders.
ForeColorGets or sets the color of the default comment indicator.
GraphicsGets an object used for painting. Inherited from CustomDrawObjectEventsArgs.
HandledGets or sets whether an event is handled. If true, the default actions are not required. Inherited from CustomDrawObjectEventsArgs.
SizeGets or sets the size of the default comment indicator in units of measurement that are currently in effect.

The event data class exposes the following methods:

MethodDescription
DrawDefault()Renders the element using the default drawing mechanism. Inherited from CustomDrawObjectEventsArgs.

Remarks

The CustomDrawCommentIndicator event fires for each visible cell that has a comment and allows you to paint comment indicators in a custom manner.

If you manually draw the indicators, set the event’s CustomDrawObjectEventsArgs.Handled parameter to true. To display the standard comment indicator, call the CustomDrawObjectEventsArgs.DrawDefault method.

The following examples demonstrate how to handle the CustomDrawCommentIndicator event to change the appearance of comment indicators.

Change the default comment indicator’s size and color

You can use the event’s Size and ForeColor properties to change the size and color of the standard comment indicator.

csharp
spreadsheetControl1.CustomDrawCommentIndicator += (s, e) => {
    e.Size = 10;
    e.ForeColor = Color.FromArgb(0x21, 0x73, 0x46);
};
vb
AddHandler SpreadsheetControl1.CustomDrawCommentIndicator,
    Sub(s, e)
        e.Size = 10
        e.ForeColor = Color.FromArgb(&H21, &H73, &H46)
    End Sub

Change a comment indicator’s shape

The code snippet below shows how to use the e.Cache.FillRectangle method to display a square comment indicator.

csharp
spreadsheetControl1.CustomDrawCommentIndicator += (s, e) => {
    int size = e.Size;
    e.Cache.FillRectangle(e.Cache.GetSolidBrush(Color.FromArgb(0x21, 0x73, 0x46)), e.CellBounds.Right - size, e.CellBounds.Top, size, size);
    e.Handled = true;
};
vb
AddHandler SpreadsheetControl1.CustomDrawCommentIndicator,
    Sub(s, e)
        Dim size As Integer = e.Size
        e.Cache.FillRectangle(e.Cache.GetSolidBrush(Color.FromArgb(&H21, &H73, &H46)), e.CellBounds.Right - size, e.CellBounds.Top, size, size)
        e.Handled = True
    End Sub

Display an image as a comment indicator

The code snippet below shows how to use the e.Cache.DrawImage method to display an image instead of a comment indicator.

csharp
Image commentImage = Image.FromFile("Comment.png");

spreadsheetControl1.CustomDrawCommentIndicator += (s, e) => {
    e.Cache.DrawImage(commentImage, e.CellBounds.Right - commentImage.Width, e.CellBounds.Top);
    e.Handled = true;
};
vb
Dim commentImage As Image = Image.FromFile("Comment.png")

AddHandler SpreadsheetControl1.CustomDrawCommentIndicator,
    Sub(s, e)
        e.Cache.DrawImage(commentImage, e.CellBounds.Right - commentImage.Width, e.CellBounds.Top)
        e.Handled = True
    End Sub

See Also

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace