SubDocument.CreateCustomMark(DocumentPosition, Object) Method
OBSOLETE
This method has become obsolete. Use the 'Create' method instead.
Creates a custom mark at the specified position and associates specified data with it.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v19.2.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
position | DocumentPosition | A DocumentPosition specifying the position being marked. |
userData | Object | An arbitrary object that will be associated with the created mark. |
Returns
Type | Description |
---|---|
CustomMark | A CustomMark object representing a position marker in the document. |
Remarks
Use the SubDocument.CreateCustomMark
method to create a mark, add it to the SubDocument.CustomMarks collection and visualize it by handling the RichEditControl.CustomMarkDraw event.
Note
A custom mark is linked to a certain text run, and moves with the content if a text is deleted or inserted before the marked position. It is not saved when the document is exported to any format, and you should provide a way to create it again when a document is loaded.
This code snippet illustrates the use of the SubDocument.CreateCustomMark
method and the RichEditControl.CustomMarkDraw event, to add a mark to the selection and draw its visual representation.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-draw-custom-marks-in-the-document-e2590
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
Dim 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)
Next info
End Sub
CreateCustomMark(DocumentPosition, Object)