locked
Rich Text Box in a windows form RRS feed

  • Question

  • I'm using the Rich Text Box in a Windows app, and I have been asked if we can add a font size of 8.5 to all fonts. Is this possible? I could not find anything about adding a custom size of 8.5, so before I tell the user that this is not possible I wanted to post the question.

    If this is possible to do, please let me know how to add the code. (C#).

    Thanks in advance

    Dan Plocica


    Dan1104

    Thursday, August 14, 2014 1:02 PM

All replies

  • You can set the RichTextBox's SelectionFont and SelectionColor in the code to change its font, e.g:

     public Form1()
            {
                InitializeComponent();
                
                richTextBox1.SelectionFont = new Font("Tahoma", 25, FontStyle.Bold);
                richTextBox1.SelectionColor = System.Drawing.Color.Red;
     }
    

    Thursday, August 14, 2014 1:06 PM
  • Thanks for the response, but I need to be able to add 8.5 as the font size. When I try your suggestion I get build errors. I even tried:

    richTextBox1.SelectionFont = new Font("Tahoma", (float)8.5, FontStyle.Regular);


    Dan1104

    Thursday, August 14, 2014 1:10 PM
  • Thanks for the response, but I need to be able to add 8.5 as the font size. When I try your suggestion I get build errors. I even tried:

    richTextBox1.SelectionFont = new Font("Tahoma", (float)8.5, FontStyle.Regular);


    Dan1104


    Try this:

    richTextBox1.SelectionFont = new Font("Tahoma", 8.5f, FontStyle.Regular);


    The above to Windows Forms only. If you are developing a WPF application, you could add a Run element to the FlowDocument and set its FontSize property:

            <RichTextBox x:Name="richTextBox1">
                <FlowDocument>
                    <Paragraph>
                        <Run FontSize="8.5" FontFamily="Tahoma" Text=""/>
                    </Paragraph>
                </FlowDocument>
            </RichTextBox>

    Thursday, August 14, 2014 1:19 PM
  • Thanks, but that didn't work, no build errors. It looks like the control doesn't accept half size font sizes.

    Dan1104

    Thursday, August 14, 2014 1:31 PM