windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-16e0a120.md
Fires before a custom mark is painted, and enables you to visualize the custom mark as required.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public event RichEditCustomMarkDrawEventHandler CustomMarkDraw
Public Event CustomMarkDraw As RichEditCustomMarkDrawEventHandler
The CustomMarkDraw event's data class is RichEditCustomMarkDrawEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Graphics | Gets an object used for painting. |
| VisualInfoCollection | Provides access to information required to visualize custom marks. |
Use the CustomMarkCollection.Create method to create a mark, add it to the SubDocument.CustomMarks collection and visualize it by handling the CustomMarkDraw event.
This code snippet illustrates the use of the CustomMarkCollection.Create method and the RichEditControl.CustomMarkDraw event, to add a mark to the selection and draw its visual representation.
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit.Layout.Export;
using System.Drawing.Drawing2D;
private void btn_Mark_Click(object sender, EventArgs e)
{
Document doc = richEditControl1.Document;
CustomMark m = doc.CustomMarks.Create(doc.Selection.Start, Color.DarkOrange);
}
private void richEditControl1_CustomMarkDraw(object sender, DevExpress.XtraRichEdit.RichEditCustomMarkDrawEventArgs e)
{
foreach (CustomMarkVisualInfo info in e.VisualInfoCollection)
{
Document doc = richEditControl1.Document;
CustomMark mark = doc.CustomMarks.GetByVisualInfo(info);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Color curColor = (Color)info.UserData;
if (mark.Position < doc.Selection.Start) { curColor = Color.Green; }
using (Pen p = new Pen(curColor, 3))
{
p.StartCap = LineCap.Flat;
p.EndCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, new Point(0, info.Bounds.Y), info.Bounds.Location);
}
}
}
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit.Layout.Export
Imports System.Drawing.Drawing2D
Private Sub btn_Mark_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Mark.Click
Dim doc As Document = richEditControl1.Document
Dim m As CustomMark = doc.CustomMarks.Create(doc.Selection.Start, Color.DarkOrange)
End Sub
Private Sub richEditControl1_CustomMarkDraw(ByVal sender As Object, ByVal e As DevExpress.XtraRichEdit.RichEditCustomMarkDrawEventArgs) Handles richEditControl1.CustomMarkDraw
For Each info As CustomMarkVisualInfo In e.VisualInfoCollection
Dim doc As Document = richEditControl1.Document
Dim mark As CustomMark = doc.CustomMarks.GetByVisualInfo(info)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim curColor As Color = CType(info.UserData, Color)
If mark.Position < doc.Selection.Start Then
curColor = Color.Green
End If
Using p As New Pen(curColor, 3)
p.StartCap = LineCap.Flat
p.EndCap = LineCap.ArrowAnchor
e.Graphics.DrawLine(p, New Point(0, info.Bounds.Y), info.Bounds.Location)
End Using
Next info
End Sub
See Also