private void btnSetRange_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (coloredRange != null) { ResetRange(coloredRange); } coloredRange = richEditControl1.Document.Selection; if (coloredRange.Length == 0) { return; } // Highlight selected range. SubDocument d = coloredRange.BeginUpdateDocument(); CharacterProperties cp = d.BeginUpdateCharacters(coloredRange); cp.BackColor = System.Drawing.Color.Yellow; d.EndUpdateCharacters(cp); coloredRange.EndUpdateDocument(d); // Create a new iterator limited to the specified range. layoutIterator = new LayoutIterator(richEditControl1.DocumentLayout, coloredRange); doc = coloredRange.BeginUpdateDocument(); richEditControl1.Document.ChangeActiveDocument(doc); coloredRange.EndUpdateDocument(doc); // Select the first element in the highlighted range. RangedLayoutElement el = richEditControl1.DocumentLayout.GetElement(coloredRange.Start, LayoutType.PlainTextBox); while (layoutIterator.MoveNext()) { RangedLayoutElement element = layoutIterator.Current as RangedLayoutElement; if ((element != null) && (element.Equals(el))) { UpdateInfoAndSelection(); return; } } }
private void btnStartHere_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (coloredRange != null) { ResetRange(coloredRange); } doc = richEditControl1.Document.CaretPosition.BeginUpdateDocument(); richEditControl1.Document.ChangeActiveDocument(doc); layoutIterator = new LayoutIterator(richEditControl1.DocumentLayout, doc.Range); RangedLayoutElement el = richEditControl1.DocumentLayout.GetElement(richEditControl1.Document.CaretPosition, LayoutType.PlainTextBox); do { RangedLayoutElement element = layoutIterator.Current as RangedLayoutElement; if ((element != null) && (element.Equals(el))) { UpdateInfoAndSelection(); return; } } while (layoutIterator.MoveNext()); }