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


C# TextRange.Select方法代码示例

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


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

示例1: UserControl_IsVisibleChanged

        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                // Show the story, hide the editor
                StoryViewBorder.Visibility = Visibility.Visible;
                StoryEditBorder.Visibility = Visibility.Hidden;

                // Load the person story into the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));

                // Hide the photo tags and photo edit buttons if there is no main photo.
                if (DisplayPhoto.Source == null)
                {
                    TagsStackPanel.Visibility = Visibility.Hidden;
                    PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
                }

                // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:28,代码来源:PersonInfo.xaml.cs

示例2: Paste_RequestNavigate

 private void Paste_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     MemoryStream ms;
     StringBuilder sb = new StringBuilder();
     foreach (String dataFormat in _listOfFormats)
     {
         if (tr.CanSave(dataFormat))
         {
             ms = new MemoryStream();
             tr.Save(ms, dataFormat);
             ms.Seek(0, SeekOrigin.Begin);
             sb.AppendLine(dataFormat);
             foreach (char c in ms.ToArray().Select<byte, char>((b) => (char)b))
             {
                 sb.Append(c);
             }
             sb.AppendLine();
         }
         //_tb.Text = sb.ToString();
     }
 }
开发者ID:jithuin,项目名称:infogeezer,代码行数:25,代码来源:LinkRichTextView.xaml.cs

示例3: OnSkinChanged

 /// <summary>
 /// The details of a person changed.
 /// </summary>
 public void OnSkinChanged()
 {
     // Display all text in constrast color to the StoryViewer background.
     TextRange textRange = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
     textRange.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
     textRange.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
 }
开发者ID:olcayseker,项目名称:PostSharp-Toolkits,代码行数:10,代码来源:PersonInfo.xaml.cs

示例4: Redo

        public override void Redo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;
            __DataStream.Seek(0, SeekOrigin.Begin);
            TextRange whole = new TextRange(document.ContentStart, document.ContentEnd);

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
            TextPointer end = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, __OffsetEnd);

            whole.Select(start, end);
            whole.Load(__DataStream, DataFormats.Xaml);

            edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionAfter);
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:14,代码来源:UndoPaste.cs

示例5: LoadPlainText

 private void LoadPlainText(string text,ref FlowDocumentReader fdr)
 {
     fdr.Document.PageWidth=816;
     TextRange tr=
     new TextRange
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentEnd
     )
     {
     Text=text
     };
     tr.Select
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentStart
     );
 }
开发者ID:DP458,项目名称:Clipboard_Watcher,代码行数:18,代码来源:MainWindow.UI.FlowDocReader.cs

示例6: UserControl_IsVisibleChanged

        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                // Load the person story into the viewer
                LoadStoryText(StoryViewer.Document);
                StoryViewBorder.Visibility = Visibility.Visible;

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);

                // Hide the Story Edit
                StoryEditBorder.Visibility = Visibility.Hidden;

                if (DisplayPhoto.Source == null)
                {
                    TagsStackPanel.Visibility = Visibility.Hidden;
                    PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
                }
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:23,代码来源:PersonInfo.xaml.cs

示例7: Window_Closing

 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     if (tr.CanSave(DataFormats.Xaml))
     {
         FileInfo fi = new FileInfo("proba.xaml");
         if (fi.Exists)
             fi.Delete();
         FileStream fs = fi.Create();
         tr.Save(fs, DataFormats.Xaml);
         fs.Flush();
         fs.Close();
     }
 }
开发者ID:jithuin,项目名称:infogeezer,代码行数:17,代码来源:LinkRichTextView.xaml.cs

示例8: PasteMergeableTextFragment

        // Helper for PasteTextFragment
        private static void PasteMergeableTextFragment(TextElement fragment, TextRange range, TextPointer insertionPosition)
        {
            TextPointer fragmentStart;
            TextPointer fragmentEnd;

            if (fragment is Span)
            {
                // Split structure at insertion point in target
                insertionPosition = TextRangeEdit.SplitFormattingElements(insertionPosition, /*keepEmptyFormatting:*/false);
                Invariant.Assert(insertionPosition.Parent is Paragraph, "insertionPosition must be in a scope of a Paragraph after splitting formatting elements");

                // Move the whole Span into the insertion point
                fragment.RepositionWithContent(insertionPosition);

                // Store edge positions of inserted content
                fragmentStart = fragment.ElementStart;
                fragmentEnd = fragment.ElementEnd;

                // Remove wrapper from a tree
                fragment.Reposition(null, null);
                ValidateMergingPositions(typeof(Inline), fragmentStart, fragmentEnd);

                // Transfer inheritable contextual properties
                ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);
            }
            else
            {
                // Correct leading nested List elements in the fragment
                CorrectLeadingNestedLists((Section)fragment);

                // Split a paragraph at insertion position
                bool needFirstParagraphMerging = SplitParagraphForPasting(ref insertionPosition);

                // Move the whole Section into the insertion point
                fragment.RepositionWithContent(insertionPosition);

                // Store edge positions of inserted content
                fragmentStart = fragment.ElementStart;
                fragmentEnd = fragment.ElementEnd.GetPositionAtOffset(0, LogicalDirection.Forward); // need forward orientation to stick with the following content during merge at fragmentStart position

                // And unwrap the root Section
                fragment.Reposition(null, null);
                ValidateMergingPositions(typeof(Block), fragmentStart, fragmentEnd);

                // Transfer inheritable contextual properties
                ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);

                // Merge paragraphs on fragment boundaries
                if (needFirstParagraphMerging)
                {
                    MergeParagraphsAtPosition(fragmentStart, /*mergingOnFragmentStart:*/true);
                }

                // Get an indication that we need to merge last paragraph
                if (!((Section)fragment).HasTrailingParagraphBreakOnPaste)
                {
                    MergeParagraphsAtPosition(fragmentEnd, /*mergingOnFragmentStart:*/false);
                }
            }

            // 

            // For paragraph pasting move range end to the following paragraph, because
            // it must include an ending paragraph break (in case of no-merging)
            if (fragment is Section && ((Section)fragment).HasTrailingParagraphBreakOnPaste)
            {
                fragmentEnd = fragmentEnd.GetInsertionPosition(LogicalDirection.Forward);
            }

            // Select pasted content
            range.Select(fragmentStart, fragmentEnd);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:73,代码来源:TextRangeSerialization.cs

示例9: PasteNonMergeableTextFragment

        // Helper for PasteTextFragment
        private static void PasteNonMergeableTextFragment(TextElement fragment, TextRange range)
        {
            // We cannot split Hyperlink or other non-splittable inline ancestor.
            // Paste text content of fragment in such case.

            // Get text content to be pasted.
            string fragmentText = TextRangeBase.GetTextInternal(fragment.ElementStart, fragment.ElementEnd);

            // Paste text into our empty target range.
            // 
            range.Text = fragmentText;
            
            // Select pasted content
            range.Select(range.Start, range.End);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:16,代码来源:TextRangeSerialization.cs

示例10: ResetTextColor

        /// <summary>
        /// resets the colors for all of the text in the given text box
        /// </summary>
        /// <param name="box"></param>
        private static void ResetTextColor(RichTextBox box)
        {
            var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);

            var startPos = GetPoint(box.Document.ContentStart, 0);

            textRange.Select(box.Document.ContentStart, box.Document.ContentEnd);
            textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
                    new SolidColorBrush(Colors.Black));

            textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
                    new SolidColorBrush(Colors.White));
        }
开发者ID:yas4891,项目名称:MUTEX,代码行数:17,代码来源:MainWindow.xaml.cs

示例11: ColorizeText

        private static void ColorizeText(RichTextBox box, int offset, int length)
        {
            var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);

            var startPos = GetPoint(box.Document.ContentStart, offset);

            var endPos = GetPoint(box.Document.ContentStart, offset + length);
            Console.WriteLine("{0},offset from start:{1}, end: {2}", box.Name, box.Document.ContentStart.GetOffsetToPosition(startPos), endPos);

            textRange.Select(startPos, endPos);

            textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
                    new SolidColorBrush(_ltForeground[_indexColorLookup % _ltForeground.Length]));

            textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
                    new SolidColorBrush(_ltBackground[_indexColorLookup % _ltForeground.Length]));
        }
开发者ID:yas4891,项目名称:MUTEX,代码行数:17,代码来源:MainWindow.xaml.cs

示例12: SaveText

 private void SaveText(ref FlowDocumentReader fdr)
 {
     string mask="Rich Text Format (*.rtf)|*.rtf|"+app.Language.TextDocument+" (*.txt)|*.txt|"+app.Language.AllFiles+" (*.*)|*.*";
     SaveFileDialog Save=CreateSaveDialog(mask,app.Language.Save);
     if(Save.ShowDialog(this).GetValueOrDefault())
     {
     FileStream file=SafeFileMethods.CreateFile(Save.FileName);
     if(file==null)
     {
     ShowNotification(app.Language.SaveTextError,Title,System.Windows.Forms.ToolTipIcon.Error);
     return;
     }
     TextRange tr=new TextRange(fdr.Document.ContentStart,fdr.Document.ContentEnd);
     tr.Select(fdr.Document.ContentStart,fdr.Document.ContentEnd);
     if(Save.FilterIndex>1)
     tr.Save(file,DataFormats.Text);
     else tr.Save(file,DataFormats.Rtf);
     tr.Select(fdr.Document.ContentStart,fdr.Document.ContentStart);
     file.Close();
     }
 }
开发者ID:DP458,项目名称:Clipboard_Watcher,代码行数:21,代码来源:MainWindow.Save.cs

示例13: SaveStoryButton_Click

        private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
        {
            Person person = (Person)this.DataContext;

            if (person != null)
            {
                // Pass in a TextRange object to save the story     
                TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
                person.Story = new Story();
                string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
                person.Story.Save(textRange, storyFileName);

                // Display the rich text in the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
            }

            StoryEditBorder.Visibility = Visibility.Hidden;
            StoryViewBorder.Visibility = Visibility.Visible;
        }
开发者ID:ssickles,项目名称:archive,代码行数:24,代码来源:PersonInfo.xaml.cs

示例14: SaveStoryButton_Click

        private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
        {
            Person person = (Person)this.DataContext;

            if (person != null)
            {
                // Pass in a TextRange object to save the story     
                TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
                person.Story = new Story();
                string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
                person.Story.Save(textRange, storyFileName);

                // Display the rich text in the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
            }

            // Switch to view mode
            StoryEditBorder.Visibility = Visibility.Hidden;
            StoryViewBorder.Visibility = Visibility.Visible;

            // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
            StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
            StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
        }
开发者ID:ssickles,项目名称:archive,代码行数:29,代码来源:PersonInfo.xaml.cs

示例15: MergeCells

        // ....................................................................
        // 
        // Cell editing
        //
        // ....................................................................
 
        /// <summary>
        /// Merges several cells horizontally. 
        /// </summary> 
        /// <param name="textRange">
        /// TextRange contining cells to be merged. 
        /// </param>
        /// <returns>
        /// TextRange containing resulted merged cell.
        /// Null in case if textRange cannot be merged. 
        /// </returns>
        internal static TextRange MergeCells(TextRange textRange) 
        { 
            Invariant.Assert(textRange != null, "null check: textRange");
 
            TableCell startCell;
            TableCell endCell;
            TableRow startRow;
            TableRow endRow; 
            TableRowGroup startRowGroup;
            TableRowGroup endRowGroup; 
            Table startTable; 
            Table endTable;
            if (!IdentifyTableElements(textRange.Start, textRange.End, /*includeCellAtMovingPosition:*/false, out startCell, out endCell, out startRow, out endRow, out startRowGroup, out endRowGroup, out startTable, out endTable)) 
            {
                return null;
            }
 
            if (startCell == null || endCell == null)
            { 
                return null; 
            }
 
            Invariant.Assert(startCell.Row.RowGroup == endCell.Row.RowGroup, "startCell and endCell must belong to the same RowGroup");
            Invariant.Assert(startCell.Row.Index <= endCell.Row.Index, "startCell.Row.Index must be <= endCell.Row.Index");
            Invariant.Assert(startCell.ColumnIndex <= endCell.ColumnIndex + endCell.ColumnSpan - 1, "startCell.ColumnIndex must be <= an index+span of an endCell");
 
            // Perform a merge
            TextRange result = MergeCellRange(startCell.Row.RowGroup, // 
                startCell.Row.Index, // topRow 
                endCell.Row.Index + endCell.RowSpan - 1, // bottomRow
                startCell.ColumnIndex, // leftColumn 
                endCell.ColumnIndex + endCell.ColumnSpan - 1); // rightColumn

            if (result != null)
            { 
                textRange.Select(textRange.Start, textRange.End);
            } 
 
            return result;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:56,代码来源:TextRangeEditTables.cs


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