void richEditControl1_CustomMarkDraw(object sender, RichEditCustomMarkDrawEventArgs e) { if (e.VisualInfoCollection != null) { Dictionary <DocumentRange, Rectangle> table = new Dictionary <DocumentRange, Rectangle>(); foreach (CustomMarkVisualInfo viewInfo in e.VisualInfoCollection) { DocumentRange range = viewInfo.UserData as DocumentRange; if (!table.ContainsKey(range)) { table.Add(range, Rectangle.Empty); } DevExpress.XtraRichEdit.API.Native.CustomMark mark = this.richEditControl1.Document.CustomMarks.GetByVisualInfo(viewInfo); Rectangle bounds = table[range]; Rectangle newBounds; if (mark.Position == range.Start) { newBounds = Rectangle.FromLTRB(viewInfo.Bounds.Left, viewInfo.Bounds.Top, bounds.Right, bounds.Bottom); } else { newBounds = Rectangle.FromLTRB(bounds.Left, bounds.Top, viewInfo.Bounds.Right, viewInfo.Bounds.Bottom); } table[range] = newBounds; } using (Brush brush = new SolidBrush(Color.FromArgb(100, Color.Yellow))) { foreach (Rectangle rect in table.Values) { e.Graphics.FillRectangle(brush, rect); } } } }
void ClearCustomMarks() { for (int i = Control.Document.CustomMarks.Count - 1; i >= 0; i--) { DevExpress.XtraRichEdit.API.Native.CustomMark mark = Control.Document.CustomMarks[i]; Control.Document.CustomMarks.Remove(mark); } }