當前位置: 首頁>>代碼示例>>C#>>正文


C# Paragraph.GetTextAfter方法代碼示例

本文整理匯總了C#中System.Windows.Documents.Paragraph.GetTextAfter方法的典型用法代碼示例。如果您正苦於以下問題:C# Paragraph.GetTextAfter方法的具體用法?C# Paragraph.GetTextAfter怎麽用?C# Paragraph.GetTextAfter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Documents.Paragraph的用法示例。


在下文中一共展示了Paragraph.GetTextAfter方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExtractListOfWords

        private List<string> ExtractListOfWords(Paragraph paragraph)
        {
            var caretIsWithin = (this.CaretPosition != null &&
                                 this.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
                                 this.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);

            var list = new List<string>();

            if (caretIsWithin)
            {
                var beforeText = paragraph.GetTextBefore(this.CaretPosition);
                var afterText = paragraph.GetTextAfter(this.CaretPosition);
                // enter key was pressed
                if (beforeText == "" && afterText == "")
                {

                    if (this.DisableAddingWhiteSpacesOnEnter)
                    {
                        return null;
                    }
                    // add white space to the new line - same as the previous line
                    var prev = paragraph.PreviousBlock as Paragraph;
                    if (prev != null)
                    {
                        var previousLine = prev.GetText();
                        var spaces = new StringBuilder();
                        foreach (var ch in previousLine)
                        {
                            if (ch == ' ' || ch == '\t')
                            {
                                spaces.Append(ch);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (spaces.Length > 0)
                        {
                            beforeText = spaces.ToString();
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
                        return null;
                    }
                }
                // else

                if (beforeText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(beforeText));
                list.Add(null);
                if (afterText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(afterText));
            }
            else
            {
                var text = paragraph.GetText();
                var array = this._paragraphProcessor.SplitWordsRegex.Split(text);
                list.AddRange(array);
            }
            return list;
        }
開發者ID:VahidN,項目名稱:PdfReport,代碼行數:65,代碼來源:SourceCodeEditor.cs

示例2: ExtractListOfWords

        /// <summary>
        /// 
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        private List<string> ExtractListOfWords(RichTextBox textBox, Paragraph paragraph)
        {
            // Check if caret position is within the word
            var caretIsWithin = (textBox.CaretPosition != null &&
                                 textBox.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
                                 textBox.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);

            var list = new List<string>();

            // If caret is within the paragraph, we need to break it up into Inline objects and format the line
            if (caretIsWithin) {

                var beforeText = paragraph.GetTextBefore(textBox.CaretPosition);
                var afterText = paragraph.GetTextAfter(textBox.CaretPosition);

                // If there's no text on either side of the caret, we're on an empty line
                if (beforeText == "" && afterText == "") {

                    if (this.DisableAddingWhiteSpacesOnEnter) {
                        return null;
                    }

                    // Add white space to the new line - same as the previous line
                    var prev = paragraph.PreviousBlock as Paragraph;
                    if (prev != null) {
                        var previousLine = prev.GetText();
                        var spaces = new StringBuilder();

                        foreach (var ch in previousLine) {
                            if (ch == ' ' || ch == '\t') {
                                spaces.Append(ch);
                            }
                            else {
                                break;
                            }
                        }

                        if (spaces.Length > 0) {
                            beforeText = spaces.ToString();
                        }
                        else {
                            return null;
                        }
                    }
                    else {
                        return null;
                    }
                }

                // If theres text before or after the caret, split the words and add them to the list
                if (beforeText != "") {
                    list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(beforeText));
                }

                // Add null representing the caret
                list.Add(null);

                if (afterText != "") {
                    list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(afterText));
                }
            }
            else {
                // If caret is not in the paragraph, just add it as-is.
                // It would already be formatted.
                var text = paragraph.GetText();
                var array = this.syntaxProcessor.SplitWordsRegex.Split(text);
                list.AddRange(array);
            }

            return list;
        }
開發者ID:Kaffedreng,項目名稱:CodeEditor,代碼行數:77,代碼來源:TextEditorControl.cs


注:本文中的System.Windows.Documents.Paragraph.GetTextAfter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。