locked
How to change the font Size for the first line of the RichTextBox RRS feed

  • Question

  • Hi All,

        I want to change the fontSize for the first line of my RichTextBox control.

        FontSize = 16 for the first line

        FontSize = 14 for the rest of lines

        Thanks in Advance

    Regards

    Ashish


    Thursday, February 16, 2012 7:05 AM

Answers

  • Hi agrawal,

    It is hard to achieve your goal in RichTextBox I think, due to there isn't definition of line in RichTextBox. Also this function is unusual that even MS Word without such one.

    So I suggest you to use a TextBox for user to input Title or something similar with large Fontsize, and a richtextbox for user to input main body.

    Hope it helps.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Annabella Luo Friday, March 2, 2012 8:58 AM
    Monday, February 20, 2012 8:45 AM

All replies

  • hi ashish

    try this code:

    private void richTextBox1_LostFocus(object sender, RoutedEventArgs e)
            {
                bool flag = false;
                foreach (var paragraph in richTextBox1.Document.Blocks)
                {
                    var text = new TextRange(paragraph.ContentStart,
                                   paragraph.ContentEnd).Text;
                    if (!flag)
                    {
                        paragraph.FontSize = 14;
                        flag = true;
                    }
                    else
                        paragraph.FontSize = 16;

                 
              }
    }

    this will work but on lost focus..

    if you find this post useful,please mark it as helpful and/or mark as answer.

    regards,

    parsita

    Thursday, February 16, 2012 4:18 PM
  • Hi Parsita,

                 Thanks for the reply, But according the reqirement i have to change the fontsize while editing(at the time of typing in the richTextBox).

    Any idea of how to do it.

    Regards

    Ashish



    Friday, February 17, 2012 5:02 AM
  • Hi agrawal,

    It is hard to achieve your goal in RichTextBox I think, due to there isn't definition of line in RichTextBox. Also this function is unusual that even MS Word without such one.

    So I suggest you to use a TextBox for user to input Title or something similar with large Fontsize, and a richtextbox for user to input main body.

    Hope it helps.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Annabella Luo Friday, March 2, 2012 8:58 AM
    Monday, February 20, 2012 8:45 AM
  • We are temporarily marking this as "Answer", if you have any concerns or new findings; please feel free to let me know.

    Best regards.



    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 2, 2012 8:58 AM