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


C# Documents.TextRange类代码示例

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


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

示例1: Write

        public void Write(string outputPath, FlowDocument doc)
        {
            Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
            Font textFont = new Font(baseFont, DEFAULT_FONTSIZE, Font.NORMAL, BaseColor.BLACK);
            Font headingFont = new Font(baseFont, DEFAULT_HEADINGSIZE, Font.BOLD, BaseColor.BLACK);
            using (FileStream stream = new FileStream(outputPath, FileMode.Create))
            {
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                foreach (Block i in doc.Blocks) {
                    if (i is System.Windows.Documents.Paragraph)
                    {
                        TextRange range = new TextRange(i.ContentStart, i.ContentEnd);
                        Console.WriteLine(i.Tag);
                        switch (i.Tag as string)
                        {
                            case "Paragraph": iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(range.Text, textFont);
                                par.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(par);
                                              break;
                            case "Heading": iTextSharp.text.Paragraph head = new iTextSharp.text.Paragraph(range.Text, headingFont);
                                              head.Alignment = Element.ALIGN_CENTER;
                                              head.SpacingAfter = 10;
                                              pdfDoc.Add(head);
                                              break;
                            default:          iTextSharp.text.Paragraph def = new iTextSharp.text.Paragraph(range.Text, textFont);
                                              def.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(def);
                                              break;

                        }
                    }
                    else if (i is System.Windows.Documents.List)
                    {
                        iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
                        list.SetListSymbol("\u2022");
                        list.IndentationLeft = 15f;
                        foreach (var li in (i as System.Windows.Documents.List).ListItems)
                        {
                            iTextSharp.text.ListItem listitem = new iTextSharp.text.ListItem();
                            TextRange range = new TextRange(li.Blocks.ElementAt(0).ContentStart, li.Blocks.ElementAt(0).ContentEnd);
                            string text = range.Text.Substring(1);
                            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(text, textFont);
                            listitem.SpacingAfter = 10;
                            listitem.Add(par);
                            list.Add(listitem);
                        }
                        pdfDoc.Add(list);
                    }

               }
                if (pdfDoc.PageNumber == 0)
                {
                    iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(" ");
                    par.Alignment = Element.ALIGN_JUSTIFIED;
                    pdfDoc.Add(par);
                }
               pdfDoc.Close();
            }
        }
开发者ID:drdaemos,项目名称:ODTCONVERTvs10,代码行数:60,代码来源:PDFWriter.cs

示例2: SetText

        /// <summary>
        /// Converts the XHtml content to XAML and sets the converted content in a flow document.
        /// </summary>
        /// <param name="document">The flow document in which the XHtml content has to be loaded.</param>
        /// <param name="text">The Unicode UTF-8 coded XHtml text to load.</param>
        /// <exception cref="InvalidDataException">When an error occured while parsing xaml code.</exception>
        public void SetText(FlowDocument document, string text)
        {
            try
            {
                if (!string.IsNullOrEmpty(text))
                {
                    XDocument xDocument = XDocument.Parse(text);
                    string xaml = HtmlToXamlConverter.ConvertXHtmlToXaml(xDocument, false);

                    TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
                    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
                    {
                        tr.Load(ms, DataFormats.Xaml);
                    }

                    _xHtml = text;
                }
            }
            catch (Exception e)
            {
                // todo tb: Logging
                //log.Error("Data provided is not in the correct Xaml or XHtml format: {0}", e);
                throw e;
            }
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:31,代码来源:XHtmlFormatter.cs

示例3: button_Click

 private void button_Click(object sender, RoutedEventArgs e)
 {
     DateTime current = DateTime.Now.Date;
     DateTime taskTime = (DateTime)Dpick.SelectedDate;
     int result = DateTime.Compare(current, taskTime);
     if (result > 0)
     {
         MessageBox.Show("Ви не можете створити завдання на попереднє число.");
     }
     else
     {
         string richText = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text;
         Tasks task = new Tasks();
         task.taskDate = Dpick.SelectedDate.ToString();
         task.taskName = richText;
         task.taskPriority = comboBox.SelectedValue.ToString();
         task.taskStatus = defaultStatus;
         CRUD crud = new CRUD();
         task.UserID=crud.getId();
         crud.Add(task);
         //MessageBox.Show(task.taskName);
         this.Close();
     }
     
 }
开发者ID:alexanderDemyanenko,项目名称:ToDoList,代码行数:25,代码来源:Add.xaml.cs

示例4: 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

示例5: TypefaceListItem

        public TypefaceListItem(Typeface typeface)
        {
            _displayName = GetDisplayName(typeface);
            _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;

            FontFamily = typeface.FontFamily;
            FontWeight = typeface.Weight;
            FontStyle = typeface.Style;
            FontStretch = typeface.Stretch;

            var itemLabel = _displayName;

            if (_simulated)
            {
                var formatString = Properties.Resources.ResourceManager.GetString(
                    "simulated",
                    CultureInfo.CurrentUICulture
                    );
                itemLabel = string.Format(formatString, itemLabel);
            }

            Text = itemLabel;
            ToolTip = itemLabel;

            // In the case of symbol font, apply the default message font to the text so it can be read.
            if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
            {
                var range = new TextRange(ContentStart, ContentEnd);
                range.ApplyPropertyValue(FontFamilyProperty, SystemFonts.MessageFontFamily);
            }
        }
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:31,代码来源:TypefaceListItem.cs

示例6: ColorizeText

        private static void ColorizeText(RichTextBox box, string inputText)
        {
            var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
            var currentPosition = box.Document.ContentStart;
            var contentEnd = box.Document.ContentEnd;

            while(null != currentPosition && currentPosition.CompareTo(contentEnd) < 0 )
            {
                if(currentPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                {
                    var text = currentPosition.GetTextInRun(LogicalDirection.Forward);

                    var p1 = currentPosition.GetPositionAtOffset(text.IndexOf(inputText));
                    var p2 = currentPosition.GetPositionAtOffset(text.IndexOf(inputText) + inputText.Length);

                    if (null != p2 && null != p1)
                    {
                        Console.WriteLine("ind:{0}, txt:{1}, p1: {2}, p2: {3}", text.IndexOf(inputText),
                                          text, p1, p2);
                        var range = new TextRange(p1, p2);

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

                        range.ApplyPropertyValue(TextElement.BackgroundProperty,
                                                 new SolidColorBrush(
                                                     _ltBackground[_indexColorLookup%_ltForeground.Length]));
                    }
                }

                currentPosition = currentPosition.GetNextContextPosition(LogicalDirection.Forward);
            }
        }
开发者ID:yas4891,项目名称:MUTEX,代码行数:34,代码来源:MainWindow.xaml.cs

示例7: Details_Click

 private void Details_Click(object sender, RoutedEventArgs e)
 {
     RoomClass rc=new RoomClass();
     var a = this.alarmGrid.SelectedItem;
     var b = a as DataRowView;
     int _Aid = Convert.ToInt32(b.Row[0]);
     MySqlDataReader reader = rc.getHistoryAlarmImformation(_Aid);
     AlarmDetails ad = new AlarmDetails();
     TextRange _Text = new TextRange(ad.Information.Document.ContentStart, ad.Information.Document.ContentEnd);
     if (reader.Read())
     {
         ad.number.Text = reader["NUMBER"].ToString();
         ad.Ename.Text = reader["NAME"].ToString();
         ad.Etype.Text = reader["TYPE_NAME"].ToString();
         ad.Atype.Text = reader["ALARM_TYPE_NAME"].ToString();
         ad.room.Text = reader["ROOM_NAME"].ToString();
         ad.Handle_User.Text = reader["USER_NAME"].ToString();
         ad.Handle_Time.Text = reader["PROCESSING_TIME"].ToString();
         ad.Alarm_Time.Text = reader["ALARM_TIME"].ToString();
         _Text.Text = reader["REMARK"].ToString();
         ad.title.Content = reader["NUMBER"] + "  历史报警信息:";
     }
     
     ad.Owner = Window.GetWindow(this);
     ad.ShowDialog();
 }
开发者ID:uwitec,项目名称:gloryview-rfid,代码行数:26,代码来源:HistoryAlarm.xaml.cs

示例8: GetText

 /// <summary>
 /// Get text.
 /// </summary>
 /// <param name="rich">RichTextBox.</param>
 /// <returns>Text.</returns>
 public static string GetText(RichTextBox rich)
 {
     var block = rich.Document.Blocks.FirstBlock;
     if (block == null)
     {
         return string.Empty;
     }
     StringBuilder text = new StringBuilder();
     do
     {
         Paragraph paragraph = block as Paragraph;
         if (paragraph != null)
         {
             var inline = paragraph.Inlines.FirstInline;
             do
             {
                 if (0 < text.Length)
                 {
                     text.Append(Environment.NewLine);
                 }
                 TextRange range = new TextRange(inline.ContentStart, inline.ContentEnd);
                 text.Append(range.Text);
             } while ((inline = inline.NextInline) != null);
         }
     } while ((block = block.NextBlock) != null);
     return text.ToString();
 }
开发者ID:Roommetro,项目名称:Friendly.WPFStandardControls,代码行数:32,代码来源:RichTextBoxUtility.cs

示例9: OnBoundDocumentChanged

        private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox box = d as RichTextBox;

            if (box == null)
                return;

            RemoveEventHandler(box);

            string newXAML = e.NewValue as string;

            box.Document.Blocks.Clear();
            if (!string.IsNullOrEmpty(newXAML))
            {
                TextRange tr = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
                MemoryStream ms = new MemoryStream();
                StreamWriter sw = new StreamWriter(ms);
                sw.Write(newXAML);
                sw.Flush();
                tr.Load(ms, DataFormats.Rtf);
                sw.Close();
                ms.Close();
            }


            AttachEventHandler(box);

        }
开发者ID:powerhai,项目名称:Jinchen,代码行数:28,代码来源:RichTextboxHelper.cs

示例10: RichTextBoxToolbar

        public RichTextBoxToolbar()
        {
            SpecialInitializeComponent();

            cmbFontFamily.SelectionChanged += (s, e) =>
            {
                if (cmbFontFamily.SelectedValue != null && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    var value = cmbFontFamily.SelectedValue;
                    tr.ApplyPropertyValue(TextElement.FontFamilyProperty, value);
                }
            };

            cmbFontSize.SelectionChanged += (s, e) =>
            {
                if (cmbFontSize.SelectedValue != null && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    var value = ((ComboBoxItem)cmbFontSize.SelectedValue).Content.ToString();
                    tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(value));
                }
            };
            cmbFontSize.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler((s, e) =>
            {
                if (!string.IsNullOrEmpty(cmbFontSize.Text) && RichTextBox != null)
                {
                    TextRange tr = new TextRange(RichTextBox.Selection.Start, RichTextBox.Selection.End);
                    tr.ApplyPropertyValue(TextElement.FontSizeProperty, double.Parse(cmbFontSize.Text));
                }
            }));
        }
开发者ID:icsharpcode,项目名称:WpfDesigner,代码行数:32,代码来源:RichTextBoxToolbar.xaml.cs

示例11: ConvertRtfToXaml

        public static string ConvertRtfToXaml(string rtfText)
        {
            var richTextBox = new System.Windows.Controls.RichTextBox();
            if (string.IsNullOrEmpty(rtfText))
                return String.Empty;
            var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            using (var rtfMemoryStream = new MemoryStream())
            {
                using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                {
                    rtfStreamWriter.Write(rtfText);
                    rtfStreamWriter.Flush();
                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
                }
            }

            using (var rtfMemoryStream = new MemoryStream())
            {
                textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                textRange.Save(rtfMemoryStream, System.Windows.DataFormats.Xaml);
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
                {
                    return rtfStreamReader.ReadToEnd();
                }
            }
        }
开发者ID:uwcbc,项目名称:uwcbc-marimba,代码行数:28,代码来源:email.cs

示例12: GetMessageText

 private string GetMessageText()
 {
     var textSelection = new TextRange(_view.MessageTextBox.Document.ContentStart,
                                       _view.MessageTextBox.Document.ContentEnd);
     var messageText = textSelection.Text;
     return messageText;
 }
开发者ID:willmurphyscode,项目名称:MSMQCommander,代码行数:7,代码来源:CreateNewMessageViewModel.cs

示例13: TypefaceListItem

        public TypefaceListItem(Typeface typeface)
        {
            _displayName = GetDisplayName(typeface);
            _simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;

            this.FontFamily = typeface.FontFamily;
            this.FontWeight = typeface.Weight;
            this.FontStyle = typeface.Style;
            this.FontStretch = typeface.Stretch;

            string itemLabel = _displayName;

            //if (_simulated)
            //{
            //    string formatString = EpiDashboard.Properties.Resources.ResourceManager.GetString(
            //        "simulated",
            //        CultureInfo.CurrentUICulture
            //        );
            //    itemLabel = string.Format(formatString, itemLabel);
            //}

            this.Text = itemLabel;
            this.ToolTip = itemLabel;

            // In the case of symbol font, apply the default message font to the text so it can be read.
            if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
            {
                TextRange range = new TextRange(this.ContentStart, this.ContentEnd);
                range.ApplyPropertyValue(TextBlock.FontFamilyProperty, SystemFonts.MessageFontFamily);
            }
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:31,代码来源:TypefaceListItem.cs

示例14: UndoLevelStyle

        public UndoLevelStyle(OutlinerNote note)
        {
            __NoteId = note.Id;

            __Before = new MemoryStream[note.Columns.Count];
            __After = new MemoryStream[note.Columns.Count];

            __IsEmpty = true;

            for (int i = 0; i < note.Columns.Count; i++)
            {
                FlowDocument document = note.Columns[i].ColumnData as FlowDocument;
                if (document == null)
                    continue;

                __Before[i] = new MemoryStream();
                __After[i] = new MemoryStream();

                TextRange range = new TextRange(document.ContentStart, document.ContentEnd);
                range.Save(__Before[i], DataFormats.Xaml);

                if (!range.IsEmpty)
                    __IsEmpty = false;

            }
        }
开发者ID:fednep,项目名称:UV-Outliner,代码行数:26,代码来源:UndoLevelStyle.cs

示例15: InsertChar

        private void InsertChar(char c)
        {
            if (rtb.Selection.Text.Length == 0)
            {
                TextPointer insertionPosition;
                if (rtb.CaretPosition.IsAtInsertionPosition == true)
                {
                    insertionPosition = rtb.CaretPosition;
                }
                else
                {
                    insertionPosition = rtb.CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward);
                }

                if (rtb.Document.Blocks.Count == 0)
                    rtb.Document.Blocks.Add(new Paragraph(new Run()));

                int offset = rtb.Document.ContentStart.GetOffsetToPosition(insertionPosition);
                insertionPosition.InsertTextInRun(c.ToString());
                rtb.CaretPosition = rtb.Document.ContentStart.GetPositionAtOffset(offset + 1, LogicalDirection.Forward);
            }
            else
            {
                TextPointer selectionStartPosition = rtb.Selection.Start;
                TextRange selection = new TextRange(rtb.Selection.Start, rtb.Selection.End);
                selection.Text = "";
                rtb.CaretPosition.InsertTextInRun(c.ToString());
                rtb.CaretPosition = rtb.CaretPosition.GetPositionAtOffset(1, LogicalDirection.Forward);
            }
        }
开发者ID:anujgeek,项目名称:HindiTransliterator,代码行数:30,代码来源:Functions.cs


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