void InsertRowNumber(TableRow row, int rowNumber)
        {
            SubDocument   doc   = row.FirstCell.Range.BeginUpdateDocument();
            DocumentRange range = doc.InsertText(row.FirstCell.Range.Start, String.Format("{0}", rowNumber + 2));

            range.EndUpdateDocument(doc);
        }
        private void SaveSelectedRange()
        {
            DocumentRange selection   = richEditControl.Document.Selection;
            SubDocument   subDocument = selection.BeginUpdateDocument();

            sourceSelectedRange = subDocument.CreateRange(selection.Start, richEditControl.Document.Selection.Length);
            selection.EndUpdateDocument(subDocument);
        }
        void ResetRange(DocumentRange r)
        {
            SubDocument         d  = r.BeginUpdateDocument();
            CharacterProperties cp = d.BeginUpdateCharacters(r);

            cp.BackColor = System.Drawing.Color.White;
            d.EndUpdateCharacters(cp);
            r.EndUpdateDocument(d);
        }
        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 btnSelectionText_Click(object sender, EventArgs e)
 {
     #region #SelectionText
     DocumentRange range     = richEditControl1.Document.Selection;
     SubDocument   doc       = range.BeginUpdateDocument();
     string        plainText = doc.GetText(range);
     MessageBox.Show(plainText, "Selected Text");
     doc.InsertText(range.Start, "->");
     doc.InsertText(range.End, "<-");
     range.EndUpdateDocument(doc);
     #endregion #SelectionText
 }
 void InsertColumnNumbers(TableRow row)
 {
     foreach (TableCell _cell in row.Cells)
     {
         if (_cell.Index == 0)
         {
             continue;
         }
         _cell.BackgroundColor = Color.Empty;
         SubDocument   doc   = _cell.Range.BeginUpdateDocument();
         DocumentRange range = doc.InsertSingleLineText(_cell.Range.Start, String.Format("{0}", _cell.Index + 1));
         range.EndUpdateDocument(doc);
     }
 }
        static void buttonCustomAction_ItemClick_Replace(object sender, ItemClickEventArgs e)
        {
            RichEditControl richEdit  = e.Item.Tag as RichEditControl;
            DocumentRange   range     = richEdit.Document.Selection;
            int             selLength = range.Length;
            string          s         = new String('*', selLength);
            SubDocument     doc       = range.BeginUpdateDocument();

            doc.InsertSingleLineText(range.Start, s);
            DocumentRange rangeToRemove = doc.CreateRange(range.Start, selLength);

            doc.Delete(rangeToRemove);
            range.EndUpdateDocument(doc);
        }
        void biClickMe_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            #region #formatting
            DocumentRange range = richEditControl1.Document.Selection;

            SubDocument doc = range.BeginUpdateDocument();

            CharacterProperties charprop = doc.BeginUpdateCharacters(range);
            charprop.BackColor = Colors.Yellow;
            charprop.AllCaps   = true;
            doc.EndUpdateCharacters(charprop);

            ParagraphProperties parprop = doc.BeginUpdateParagraphs(range);
            parprop.Alignment = ParagraphAlignment.Center;
            doc.EndUpdateParagraphs(parprop);

            range.EndUpdateDocument(doc);
            #endregion #formatting
        }
 void InsertColumnNumbers(TableRow row)
 {
     foreach (TableCell _cell in row.Cells)
     {
         if (_cell.Index == 0)
         {
             continue;
         }
         _cell.BackgroundColor = Colors.Transparent;
         SubDocument         doc   = _cell.Range.BeginUpdateDocument();
         DocumentRange       range = doc.InsertSingleLineText(_cell.Range.Start, String.Format("{0}", _cell.Index + 1));
         CharacterProperties cp    = doc.BeginUpdateCharacters(range);
         cp.Bold      = true;
         cp.FontName  = "Comic Sans";
         cp.FontSize  = 12;
         cp.ForeColor = Colors.Red;
         doc.EndUpdateCharacters(cp);
         range.EndUpdateDocument(doc);
     }
 }
        private void ApplyFormatToSelectedText()
        {
            DocumentRange targetSelectedRange = richEditControl.Document.Selection;

            richEditControl.BeginUpdate();
            SubDocument targetSubDocument = targetSelectedRange.BeginUpdateDocument();
            SubDocument subDocument       = sourceSelectedRange.BeginUpdateDocument();

            DevExpress.XtraRichEdit.API.Native.CharacterProperties targetCharactersProperties = targetSubDocument.BeginUpdateCharacters(targetSelectedRange);
            DevExpress.XtraRichEdit.API.Native.CharacterProperties sourceCharactersProperties = subDocument.BeginUpdateCharacters(sourceSelectedRange);
            targetCharactersProperties.Assign(sourceCharactersProperties);
            subDocument.EndUpdateCharacters(sourceCharactersProperties);
            targetSubDocument.EndUpdateCharacters(targetCharactersProperties);

            DevExpress.XtraRichEdit.API.Native.ParagraphProperties targetParagraphProperties = targetSubDocument.BeginUpdateParagraphs(targetSelectedRange);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties sourceParagraphProperties = subDocument.BeginUpdateParagraphs(sourceSelectedRange);
            targetParagraphProperties.Assign(sourceParagraphProperties);
            subDocument.EndUpdateParagraphs(sourceParagraphProperties);
            targetSubDocument.EndUpdateParagraphs(targetParagraphProperties);

            sourceSelectedRange.EndUpdateDocument(subDocument);
            targetSelectedRange.EndUpdateDocument(targetSubDocument);
            richEditControl.EndUpdate();
        }