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 }
public static string GetInformationAboutCurrentTextBoxContent(LayoutTextBox currentTextBox, DocumentLayout currentLayout) { string returnedInformation = ""; CustomDocumentLayoutVisitor visitor = new CustomDocumentLayoutVisitor(); visitor.Visit(currentTextBox); SubDocument doc = currentLayout.BeginUpdateDocument(currentTextBox); string plainTextContent = doc.GetText(doc.Range); currentLayout.EndUpdateDocument(doc); returnedInformation += String.Format("Lines count: {0}\r\n", visitor.TextLinesCount); returnedInformation += String.Format("Words count: {0}\r\n", visitor.WordsCount); returnedInformation += String.Format("Plain text: {0}\r\n", plainTextContent); return(returnedInformation); }
static void ExportSelectionToPlainText(Document document) { #region #ExportSelectionToPlainText document.LoadDocument("Documents//FloatingObjects.docx", DocumentFormat.OpenXml); // Select footer. SubDocument footerDocument = document.Sections[0].BeginUpdateFooter(); document.ChangeActiveDocument(footerDocument); document.Selection = footerDocument.Paragraphs[0].Range; document.Sections[0].EndUpdateFooter(footerDocument); // Get selection as plain text. SubDocument docRange = document.Selection.BeginUpdateDocument(); string plainText = docRange.GetText(docRange.Range); document.Selection.EndUpdateDocument(docRange); DevExpress.XtraEditors.XtraMessageBox.SmartTextWrap = true; DevExpress.XtraEditors.XtraMessageBox.Show(plainText); #endregion #ExportSelectionToPlainText }
private void richEditControl1_MouseMove(object sender, MouseEventArgs e) { Point docPoint = Units.PixelsToDocuments(e.Location, richEditControl1.DpiX, richEditControl1.DpiY); DocumentPosition pos = richEditControl1.GetPositionFromPoint(docPoint); if (pos == null) { return; } DocumentPosition start = pos; DocumentPosition end = pos; SubDocument doc = richEditControl1.Document.CaretPosition.BeginUpdateDocument(); for (int i = 0; i < doc.Range.End.ToInt(); i++) { if (start.ToInt() - i < 0) { start = doc.Range.Start; break; } DocumentRange range = doc.CreateRange(start.ToInt() - i, i + 1); string str = doc.GetText(range); if (ContainsPunctuationOrWhiteSpace(str)) { start = doc.CreatePosition(range.Start.ToInt() + 1); break; } } for (int i = 0; i < doc.Range.End.ToInt(); i++) { if (end.ToInt() + i > doc.Range.End.ToInt()) { end = doc.Range.End; break; } DocumentRange range = doc.CreateRange(end.ToInt(), i + 1); string str = doc.GetText(range); if (ContainsPunctuationOrWhiteSpace(str)) { end = doc.CreatePosition(range.End.ToInt() - 1); break; } } if (end.ToInt() < start.ToInt()) { return; } DocumentRange wordRange = doc.CreateRange(start, end.ToInt() - start.ToInt()); string word = doc.GetText(wordRange); richEditControl1.Document.CaretPosition.EndUpdateDocument(doc); ShowToolTip(word); }