当前位置: 首页>>代码示例>>C#>>正文


C# TextRange.Substring方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextRange.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.Substring方法的具体用法?C# TextRange.Substring怎么用?C# TextRange.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextRange的用法示例。


在下文中一共展示了TextRange.Substring方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FlowDocument2Text

 public static String FlowDocument2Text(FlowDocument doc)
 {
     String text = new TextRange(doc.ContentStart, doc.ContentEnd).Text;
     if (text.EndsWith("\r\n"))
     {
         text = text.Substring(0, text.Length - 2);
     }
     return text;
 }
开发者ID:andrey-kozyrev,项目名称:LinguaSpace,代码行数:9,代码来源:FlowDocumentUtils.cs

示例2: richTextBox1_PreviewKeyDown

        private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (lstOptions.Visibility == Visibility.Visible)
            {
                lstOptions.Focus();
                return;
            }

            if (!IsCaretPositionValid())
            {
                this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
                return;
            }

            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }

            if (e.Key == Key.Enter)
            {
                var command = GetCommand();
                RunCommand(command);
                e.Handled = true;
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("", BRUSH_PROMPT);
                lstOptions.Visibility = Visibility.Collapsed;
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">")) e.Handled = true;
            }
        }
开发者ID:annastazi09,项目名称:Git-Source-Control-Provider,代码行数:51,代码来源:GitConsole.xaml.cs

示例3: richTextBox1_PreviewKeyDown

        private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (lstOptions.Visibility == Visibility.Visible)
            {
                if (e.Key == Key.Escape)
                {
                    this.HideOptions();
                }
                else
                {
                    lstOptions.Focus();
                }
                return;
            }

            if (!IsCaretPositionValid())
            {
                this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
                return;
            }

            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }

            if (e.Key == Key.Enter)
            {
                var command = GetCommand();
                if (this.IsProcessRunning)
                {
                    this.WriteInput(command);
                }
                else
                {
                    RunCommand(command);
                    e.Handled = true;
                }
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("", BRUSH_PROMPT);
                this.HideOptions();
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">") && text.IndexOf(">") == text.Length - 1) e.Handled = true;
            }
            else if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
            {
                if (IsProcessRunning)
                {
                    SendShutdownToConsole();
                    e.Handled = true;
                }
            }
            else if (lstOptions.Visibility == Visibility.Visible)
            {
                //lstOptions.KeyDown()
            }
        }
开发者ID:gencer,项目名称:git-tools,代码行数:77,代码来源:GitConsole.xaml.cs

示例4: adornedElement_PreviewKeyUp

        private void adornedElement_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if ((this.richTextBox != null) && (((e != null) && (e.Key == Key.Space)) || ((e == null) && this.performURLParsing)))
            {
                bool isWWWPrefixed;
                this.performURLParsing = false;
                string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.Document.ContentEnd).Text;
                string str2 = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
                int length = str2.Length;
                if (((length - 1) <= text.Length) && (length != 0))
                {
                    int startIndex = -1;
                    if ((length - 2) >= 0)
                    {
                        startIndex = text.LastIndexOf("http://", (int)(length - 2));
                        startIndex = (startIndex == -1) ? text.LastIndexOf("https://", (int)(length - 2)) : startIndex;
                        startIndex = (startIndex == -1) ? (startIndex = text.LastIndexOf("www.", (int)(length - 2))) : startIndex;
                    }
                    if (startIndex == -1)
                    {
                        startIndex = 0;
                    }
                    if (str2.Substring(0, str2.Length - 1).EndsWith("\r\n"))
                    {
                        startIndex = length - 1;
                    }
                    this.lastWord = text.Substring(startIndex, length - startIndex);
                    isWWWPrefixed = false;
                    int num3 = this.lastWord.LastIndexOf("http://");
                    num3 = (num3 == -1) ? this.lastWord.LastIndexOf("https://") : num3;
                    if (num3 == -1)
                    {
                        num3 = this.lastWord.LastIndexOf("www.");
                        isWWWPrefixed = true;
                    }
                    if (num3 != -1)
                    {
                        string url;
                        ContextMenu buttonContextMenu;
                        Button button;
                        MenuItem expandContractMenuItem;
                        MenuItem gotoLinkMenuitem;
                        Func<string> shortenURLDelegate;
                        int index = this.lastWord.IndexOf(' ', num3);
                        if (index != -1)
                        {
                            url = this.lastWord.Substring(num3, index - num3);
                            int num5 = url.Length;
                            if (isWWWPrefixed)
                            {
                                num5 += "http://".Length;
                            }
                            if ((num5 >= this.URL_LENGTH_THRESHOLD) && !this.IsAlreadyShortened(url))
                            {
                                int x = text.IndexOf(url) - GetInlineUIContainerCountUpToPointer(this.richTextBox, this.richTextBox.CaretPosition);
                                TextPointer start = new TextRange(GetPoint(this.richTextBox.Document.ContentStart, x), this.richTextBox.Document.ContentEnd).Start;
                                start.DeleteTextInRun(url.Length);
                                buttonContextMenu = new ContextMenu();
                                button = new Button();
                                button.SetResourceReference(FrameworkElement.StyleProperty, "URLButton");
                                button.Content = "shortening...";
                                button.Click += delegate(object s, RoutedEventArgs e2)
                                {
                                    buttonContextMenu.PlacementTarget = button;
                                    buttonContextMenu.Placement = PlacementMode.Bottom;
                                    buttonContextMenu.IsOpen = true;
                                };
                                expandContractMenuItem = new MenuItem
                                {
                                    Header = "Expand link",
                                    IsEnabled = false
                                };
                                gotoLinkMenuitem = new MenuItem
                                {
                                    Header = "Open link in browser",
                                    IsEnabled = false
                                };
                                buttonContextMenu.Items.Add(gotoLinkMenuitem);
                                buttonContextMenu.Items.Add(expandContractMenuItem);
                                InlineUIContainer container = new InlineUIContainer(button, start);
                                shortenURLDelegate = delegate
                                {
                                    Dictionary<string, string> dictionary = new Dictionary<string, string>();
                                    if (CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID) != null)
                                    {
                                        string key = CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID).Name;
                                        if (!App.ShortenedURLCache.ContainsKey(key))
                                        {
                                            Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
                                            App.ShortenedURLCache.Add(key, dictionary2);
                                            dictionary = dictionary2;
                                        }
                                        else
                                        {
                                            dictionary = App.ShortenedURLCache[key];
                                        }
                                    }
                                    string text1 = url;
                                    if (isWWWPrefixed)
                                    {
//.........这里部分代码省略.........
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:101,代码来源:URLAdorner.cs

示例5: GetInput

 private string GetInput(RichTextBox richTextBox) 
 {
     string input = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text;
     if (input.Length > 2)
     {
         return input.Substring(0, input.Length - 2);
     }
     else
     {
         return string.Empty;
     }
 }
开发者ID:profimedica,项目名称:SYKYO,代码行数:12,代码来源:MainWindow.xaml.cs

示例6: richTextBox1_PreviewKeyDown

        private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }
            else if (e.Key == Key.Tab || e.Key == Key.Down)
            {
                if (lstOptions.Visibility == Visibility.Visible)
                {
                    lstOptions.Focus();
                    return;
                }
            }
            else
            {
                lstOptions.Visibility = Visibility.Collapsed;
            }

            if (e.Key == Key.Enter)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition.GetLineStartPosition(1) ?? richTextBox1.CaretPosition.DocumentEnd).Text;
                command = command.Replace("\r", "").Replace("\n", "");
                RunCommand(command);
                e.Handled = true;
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("",  new SolidColorBrush(Colors.Black));
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">")) e.Handled = true;
            }
            else
            {
                var text = new TextRange(richTextBox1.CaretPosition, richTextBox1.CaretPosition.DocumentEnd).Text;
                if (text.Contains(">")) //e.Handled = true;
                    this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
            }
        }
开发者ID:JamesChan,项目名称:Git-Source-Control-Provider,代码行数:58,代码来源:GitConsole.xaml.cs

示例7: richTextBox_PreviewKeyUp

 private void richTextBox_PreviewKeyUp(object sender, KeyEventArgs e)
 {
     if (((e.Key != Key.Up) && (e.Key != Key.Down)) && ((e.Key != Key.Space) || !this.IgnorePrefix))
     {
         if ((e.Key == Key.Space) || (e.Key == Key.Escape))
         {
             this.HideMethodsPopup();
         }
         if (((((e.Key == Key.Escape) || (e.Key == Key.Left)) || ((e.Key == Key.Right) || (e.Key == Key.Return))) || ((this.IgnorePrefix && (e.Key == Key.D2)) && (Keyboard.Modifiers == ModifierKeys.Shift))) || this.ignoreDisplay)
         {
             this.HideMethodsPopup();
             this.ignoreDisplay = false;
         }
         else
         {
             IEnumerable<IntellisenseItem> results = null;
             string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
             int startIndex = text.LastIndexOf(' ');
             string input = (startIndex != -1) ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]);
             if (((input == "@") || (input == "#")) && this.IgnorePrefix)
             {
                 this.HideMethodsPopup();
                 this.ignoreDisplay = false;
             }
             else if (!(this.ExcludeMentions || (((input != "@") && !input.EndsWith("@")) && !(text == "d "))))
             {
                 results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches("@");
                 Rect rect = this.richTextBox.CaretPosition.GetCharacterRect(LogicalDirection.Forward);
                 this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate
                 {
                     this.ShowMethodsPopup(rect, this.richTextBox);
                     this.intellisenseListBox.SelectedIndex = -1;
                 });
             }
             else if ((input == "#") || input.EndsWith("#"))
             {
                 results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches("#");
                 Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward);
                 this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate
                 {
                     this.ShowMethodsPopup(rect, this.richTextBox);
                     this.intellisenseListBox.SelectedIndex = -1;
                 });
             }
             else if (!(this.ExcludeMentions || (!MENTION_EXPRESSION.IsMatch(input) && !this.IgnorePrefix)))
             {
                 string currentWordExcludingPrefix = string.Empty;
                 currentWordExcludingPrefix = this.IgnorePrefix ? input : MENTION_EXPRESSION.Match(input).Groups[1].Value;
                 results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix);
                 Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward);
                 this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate
                 {
                     this.ShowMethodsPopup(rect, this.richTextBox);
                     this.SetSelection(currentWordExcludingPrefix);
                 });
             }
             else if (!((this.ExcludeMentions || !DM_EXPRESSION.IsMatch(text)) || DM_EXPRESSION_WITH_END_SPACE.IsMatch(text)))
             {
                 string currentWordExcludingPrefix = DM_EXPRESSION.Match(text).Groups[1].Value;
                 results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix);
                 Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward);
                 this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate
                 {
                     this.ShowMethodsPopup(rect, this.richTextBox);
                     this.SetSelection(currentWordExcludingPrefix);
                 });
             }
             else if (TAG_EXPRESSION.IsMatch(input))
             {
                 string partialWord = TAG_EXPRESSION.Match(input).Groups[1].Value;
                 results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches(partialWord);
                 Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward);
                 this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate
                 {
                     this.ShowMethodsPopup(rect, this.richTextBox);
                     this.intellisenseListBox.SelectedIndex = -1;
                 });
             }
             else
             {
                 this.HideMethodsPopup();
             }
         }
     }
 }
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:85,代码来源:IntellisenseAdorner.cs

示例8: InsertSelectedEntry

 private void InsertSelectedEntry(char characterInsertion)
 {
     if (this.intellisenseListBox.SelectedIndex <= -1 || !this.intellisensePopup.IsOpen)
         return;
     string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
     int startIndex = text.LastIndexOf(' ');
     string currentWord = startIndex != -1 ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]);
     IntellisenseItem intellisenseItem = this.intellisenseListBox.SelectedItem as IntellisenseItem;
     bool flag = text.StartsWith("d ", StringComparison.InvariantCultureIgnoreCase) && !IntellisenseAdorner.DM_EXPRESSION_WITH_END_SPACE.IsMatch(text);
     string textData = this.IgnorePrefix || flag ? intellisenseItem.FilterValue : intellisenseItem.DisplayValue;
     if (textData.StartsWith("@") || textData.StartsWith("#"))
     {
         int charactersToDelete = IntellisenseAdorner.GetNumberOfCharactersToDelete(currentWord, textData.StartsWith("@") ? "@" : "#");
         if (currentWord.EndsWith(" "))
             this.richTextBox.CaretPosition.DeleteTextInRun(-(charactersToDelete - 1));
         else
             this.richTextBox.CaretPosition.DeleteTextInRun(-charactersToDelete);
     }
     else if (currentWord.EndsWith(" "))
         this.richTextBox.CaretPosition.DeleteTextInRun(-(currentWord.Length - 1));
     else
         this.richTextBox.CaretPosition.DeleteTextInRun(-currentWord.Length);
     if ((int)characterInsertion != 0 && !this.IgnorePrefix)
         textData = textData + (object)characterInsertion;
     this.richTextBox.CaretPosition = this.richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? this.richTextBox.CaretPosition;
     if (!flag)
     {
         this.richTextBox.CaretPosition.InsertTextInRun(textData);
     }
     else
     {
         this.richTextBox.CaretPosition.InsertTextInRun(textData);
         Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)intellisenseItem.FilterValue), (object)CommonCommands.MultiAccountifyToken((Enum)ViewModelMessages.DirectMessage, intellisenseItem.TwitterAccountID));
     }
     this.ignoreDisplay = true;
 }
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:36,代码来源:IntellisenseAdorner.cs


注:本文中的System.Windows.Documents.TextRange.Substring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。