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


C# Controls.RichTextBox类代码示例

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


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

示例1: Convert

        private void Convert()
        {
            var richTextBox = new RichTextBox();
            if (string.IsNullOrEmpty(_rtf))
            {
                _convertedRtf = string.Empty;
                return;
            }

            var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

            // Create a MemoryStream of the Rtf content
            using (var rtfMemoryStream = new MemoryStream())
            using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
            {
                rtfStreamWriter.Write(_rtf);
                rtfStreamWriter.Flush();
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);

                // Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
                textRange.Load(rtfMemoryStream, DataFormats.Rtf);
            }

            using (var rtfMemoryStream = new MemoryStream())
            {
                textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                textRange.Save(rtfMemoryStream, DataFormats.Xaml);
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
                    _convertedRtf = ConvertXamlToHtml(rtfStreamReader.ReadToEnd());
            }
        }
开发者ID:naingyelin,项目名称:msgreader,代码行数:32,代码来源:RtfToHtmlConverter.cs

示例2: Credits_Click

        private void Credits_Click(object sender, RoutedEventArgs e)
        {
            this.Mainwindow.BackGrid.Children.Clear();
            this.Mainwindow.MainGrid.Visibility = Visibility.Hidden;
            creditCanvas.Background = Brushes.White;
            creditCanvas.IsHitTestVisible = true;
            RichTextBox richTextBox1 = new RichTextBox();
            creditCanvas.Children.Add(richTextBox1);
            FileStream fs = new FileStream("Documents\\Credits\\credits.rtf", FileMode.Open, FileAccess.Read);

            TextRange RTBText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
            RTBText.Load(fs, DataFormats.Rtf);
            richTextBox1.Width = 1920;
            richTextBox1.Height = 10000;
            richTextBox1.HorizontalAlignment = HorizontalAlignment.Center;
            richTextBox1.Background = Brushes.Black;
            richTextBox1.Foreground = Brushes.WhiteSmoke;
            richTextBox1.FontFamily = new FontFamily("Segoe UI");

            richTextBox1.BorderThickness = new Thickness(0);
            TranslateTransform ttransform = new TranslateTransform();
            richTextBox1.RenderTransform= ttransform;
            DoubleAnimation scrollAnim = new DoubleAnimation(0,-10000,new Duration(TimeSpan.FromSeconds(60)),FillBehavior.Stop);
            scrollAnim.Completed += new EventHandler(scrollAnim_Completed);
            richTextBox1.ClipToBounds = true;
            //scrollAnim.RepeatBehavior = RepeatBehavior.Forever;
            ttransform.BeginAnimation(TranslateTransform.YProperty, scrollAnim);
            creditCanvas.PreviewMouseDown += new MouseButtonEventHandler(creditCanvas_PreviewMouseDown);
            this.Mainwindow.BackGrid.Children.Add(creditCanvas);
        }
开发者ID:pittruff,项目名称:myStik,代码行数:30,代码来源:Impressum.xaml.cs

示例3: FormatRichText

        public FormatRichText()
        {
            Title = "Format Rich Text";

            // Create DockPanel as content of window.
            DockPanel dock = new DockPanel();
            Content = dock;

            // Create ToolBarTray docked at top of client area.
            ToolBarTray tray = new ToolBarTray();
            dock.Children.Add(tray);
            DockPanel.SetDock(tray, Dock.Top);

            // Create RichTextBox.
            txtbox = new RichTextBox();
            txtbox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

            // Call methods in other files.
            AddFileToolBar(tray, 0, 0);
            AddEditToolBar(tray, 1, 0);
            AddCharToolBar(tray, 2, 0);
            AddParaToolBar(tray, 2, 1);
            AddStatusBar(dock);

            // Fill rest of client area with RichTextBox and give it focus.
            dock.Children.Add(txtbox);
            txtbox.Focus();
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:28,代码来源:FormatRichText.cs

示例4: IntellisenseAdorner

 public IntellisenseAdorner(RichTextBox richTextBox)
     : base((UIElement)richTextBox)
 {
     this.Unloaded += new RoutedEventHandler(this.IntellisenseAdorner_Unloaded);
     this.richTextBox = richTextBox;
     IntellisenseAdorner intellisenseAdorner1 = this;
     ListBox listBox1 = new ListBox();
     listBox1.Focusable = false;
     ListBox listBox2 = listBox1;
     intellisenseAdorner1.intellisenseListBox = listBox2;
     this.intellisenseListBox.SetResourceReference(FrameworkElement.StyleProperty, (object)"IntellisenseList");
     this.Enable();
     IntellisenseAdorner intellisenseAdorner2 = this;
     Popup popup1 = new Popup();
     popup1.AllowsTransparency = true;
     popup1.Focusable = false;
     popup1.IsOpen = false;
     popup1.Placement = PlacementMode.Top;
     popup1.PlacementTarget = (UIElement)richTextBox;
     popup1.StaysOpen = false;
     popup1.HorizontalAlignment = HorizontalAlignment.Left;
     popup1.Child = (UIElement)this.intellisenseListBox;
     Popup popup2 = popup1;
     intellisenseAdorner2.intellisensePopup = popup2;
 }
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:25,代码来源:IntellisenseAdorner.cs

示例5: URLAdorner

 public URLAdorner(UIElement adornedElement)
     : base(adornedElement)
 {
     if (!(adornedElement is RichTextBox))
         return;
     this.richTextBox = adornedElement as RichTextBox;
 }
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:7,代码来源:URLAdorner.cs

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

示例7: LoadRange

 private static void LoadRange(RichTextBox richTextBox, TextRange range)
 {
     MemoryStream buffer = new MemoryStream();
     range.Save(buffer, DataFormats.Rtf);
     var rtf = Encoding.UTF8.GetString(buffer.ToArray());
     SetContent(richTextBox, rtf);
 }
开发者ID:peterson1,项目名称:ErrH,代码行数:7,代码来源:RichTextBoxHelper.cs

示例8: HistoryWindow

        public HistoryWindow(Interlocutor interlocutor, IModelContext context)
        {
            InitializeComponent();
            _context = context;
            this.DataContext = this;
            Interlocutor = interlocutor;
            var history = new MessageRepository().LoadHistory(interlocutor) ?? new History
            {
                InterlocutorId = interlocutor.Id,
                Messages = new List<Message>()
            };
            HistoryView = new ObservableCollection<HistoryView>();

            HistoryMessages = new RichTextBox(new FlowDocument());
            HistoryMessages.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            HistoryMessages.IsReadOnly = true;

            var monthGroups = history.Messages
                .OrderByDescending(note => note.Date)
                .GroupBy(key => key.Date.ToString("MMMM yyyy"));
            foreach (var monthGroup in monthGroups)
            {
                HistoryView.Add(new HistoryView
                {
                    Month = monthGroup.Key,
                    ActiveDates = new ObservableCollection<DayMessageView>(
                        monthGroup.GroupBy(key => key.Date.ToShortDateString())
                        .Select(dayGroup => new DayMessageView
                        {
                            Day = dayGroup.Key,
                            Messages = new ObservableCollection<Message>(dayGroup)
                        }))
                });
            }
        }
开发者ID:zhongleiyang,项目名称:vstalk,代码行数:35,代码来源:HistoryWindow.xaml.cs

示例9: GetSelectedFontSize

 /// <summary>
 /// extracts the font size (double) out of the current selection of
 /// the rich text box
 /// </summary>
 /// <param name="box">the rich text box</param>
 /// <returns>the font size or null (therefore the
 /// nullable type double? is used) if the state could not
 /// be determined</returns>
 private double? GetSelectedFontSize(RichTextBox box)
 {
     var propVal = box.Selection.GetPropertyValue(FontSizeProperty);
     if (propVal == DependencyProperty.UnsetValue)
         return null;
     return (double)propVal;
 }
开发者ID:HSR-MGE,项目名称:WPF-Uebungen,代码行数:15,代码来源:MainWindow.xaml.cs

示例10: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _block = (RichTextBox)GetTemplateChild("PART_TextBlock");
            UpdateText();
        }
开发者ID:bling,项目名称:Ping.Pong,代码行数:7,代码来源:TweetTextBlock.cs

示例11: GetSelectedFontFamily

 /// <summary>
 /// extracts the font family used in the current selection of
 /// the rich text box
 /// </summary>
 /// <param name="box">the rich text box</param>
 /// <returns>the font family name or null if the state could not
 /// be determined</returns>
 private string GetSelectedFontFamily(RichTextBox box)
 {
     var propVal = box.Selection.GetPropertyValue(FontFamilyProperty);
     if (propVal == DependencyProperty.UnsetValue)
         return null;
     return ((FontFamily)propVal).Source;
 }
开发者ID:HSR-MGE,项目名称:WPF-Uebungen,代码行数:14,代码来源:MainWindow.xaml.cs

示例12: appendErrorText

 /// <summary>
 /// Append text to RichTextBox with red coloring; for errors
 /// </summary>
 /// <param name="targetBox">Box to append text to</param>
 /// <param name="text">Error text to append</param>
 private void appendErrorText(RichTextBox targetBox, string text)
 {
     // Append text with automatic styling for error text
     TextRange tr = new TextRange(targetBox.Document.ContentEnd, targetBox.Document.ContentEnd);
     tr.Text = text;
     tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
 }
开发者ID:TheQuack45,项目名称:HypeBotCSharp-old,代码行数:12,代码来源:MainWindow.xaml.cs

示例13: Create

		void Create ()
		{
			var run = new Run { Text = "Hello From The Run" };
			var paragraph = new Paragraph();
			paragraph.Inlines.Add(run);

			RichTextBox box = new RichTextBox { };
			box.Blocks.Add(paragraph);

			var insertion = box.ContentEnd.GetPositionAtOffset(-2, LogicalDirection.Backward).GetPositionAtOffset(-1, LogicalDirection.Backward);
			box.Selection.Select(insertion, insertion);
			box.Selection.Insert(new Run { Text = "ARGH" });

			if (((Paragraph)box.Blocks[0]).Inlines.Count != 3)
				Fail ("We should have three inlines");
				
			foreach (var v in ((Paragraph)box.Blocks[0]).Inlines) {
				if (v == null)
					Fail ("No inline should be null");
				runs.Add (new WeakReference (v));
			}
			
			GCAndInvoke (() => {
				foreach (var r in runs)
					if (r.Target != null)
						Fail ("The run should be GC'ed");
				Succeed ();
			});
		}
开发者ID:dfr0,项目名称:moon,代码行数:29,代码来源:Test.cs

示例14: Question

        public Question(string myFilename, RichTextBox richMain)
        {
            Filename = Path.GetFileName(myFilename);
            string xmlText = File.ReadAllText(myFilename);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlText);

            try
            {
                XmlNode xmlQD = xmlDoc.GetElementsByTagName("QuestionDesc")[0];
                XmlNode xmlQ = xmlDoc.GetElementsByTagName("QuestionText")[0];
                XmlCDataSection xmlCData = xmlQ.FirstChild as XmlCDataSection;
                XmlNode xmlAA = xmlDoc.GetElementsByTagName("AnswerA")[0];
                XmlNode xmlAB = xmlDoc.GetElementsByTagName("AnswerB")[0];
                XmlNode xmlAC = xmlDoc.GetElementsByTagName("AnswerC")[0];
                XmlNode xmlAD = xmlDoc.GetElementsByTagName("AnswerD")[0];
                XmlNode xmlT = xmlDoc.GetElementsByTagName("Time")[0];
                XmlNode xmlL = xmlDoc.GetElementsByTagName("Level")[0];
                XmlNode xmlA = xmlDoc.GetElementsByTagName("Correct")[0];

                QuestionDescripion = xmlQD.InnerText.ToString();
                QuestionText = xmlCData.InnerText;
                AnswerA = xmlAA.InnerText;
                AnswerB = xmlAB.InnerText;
                AnswerC = xmlAC.InnerText;
                AnswerD = xmlAD.InnerText;
                Correct = xmlA.InnerText;
                Time = Convert.ToInt32(xmlT.InnerText);
                Level = Convert.ToInt32(xmlL.InnerText);
            }
            catch (Exception expError)
            {
                richMain.AppendText("Problem with question file format: " + expError.Message + Environment.NewLine);
            }
        }
开发者ID:nccgroup,项目名称:44Con2013Game,代码行数:35,代码来源:Question.cs

示例15: CreateTextBox

		private static void CreateTextBox(List<DependencyObject> list, List<Inline> current, IHtmlTextBlock textBlock)
		{
			if (current.Count > 0)
			{
				var p = new Paragraph();
				foreach (var r in current)
					p.Inlines.Add(r);

#if !WINRT
				var tb = new RichTextBox();
				tb.Background = textBlock.Background;
				tb.Margin = new Thickness(-12, textBlock.ParagraphMargin, -12, textBlock.ParagraphMargin);
#else
				var tb = new RichTextBlock();
				tb.IsTextSelectionEnabled = false;
				tb.Margin = new Thickness(0, textBlock.ParagraphMargin, 0, textBlock.ParagraphMargin);
#endif
				tb.Blocks.Add(p);
				tb.Foreground = textBlock.Foreground;
				tb.FontSize = textBlock.FontSize;
				tb.FontFamily = textBlock.FontFamily;
				
				list.Add(tb);
				current.Clear();
			}
		}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:26,代码来源:ParagraphGenerator.cs


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