Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Need help with RichTextBox

$
0
0

I am building a RichTextBox in my codebehind.  Here is some simple code I'm trying to make work:

                        FlowDocument mcFlowDoc = new FlowDocument();

                        Paragraph para = new Paragraph();
                        para.Inlines.Add(new Bold(new Run("Hello World")));

                        mcFlowDoc.Blocks.Add(para);

                        RichTextBox mcRTB = new RichTextBox();
                        mcRTB.Width = 560;
                        mcRTB.Height = 280;

                        mcRTB.Document = mcFlowDoc;

                        mcRTB.SelectAll();
                        tbDirections.Text += mcRTB.Selection.Text;

Here is my xaml for tbDirections:

<TextBlock 
                   Margin="0,0,8,0"
                   Name="tbDirections"
                   Text="My driving directions..." TextWrapping="Wrap" /> 

So "Hello World" does appear at the end of my TextBlock tbDirections but it's not bold.  I am a WPF newbie.  What am I doing wrong?


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>