Coolguy
Coolguy

Reputation: 2285

C# Use different font size on a line in richtextbox

how do we use different font size on a line in the RichTextBox? Let say I want the first word to be font 10 but the second word on the same line I want it to be 20. I'm using the below:

    private void textBox10_TextChanged(object sender, EventArgs e)
    {
        richTextBox2.Font = new Font("Microsoft San Serif", 12);
        richTextBox2.Text = "\n\n" + textBox10.Text;         
    }

But it apply to whole text on the line...

Upvotes: 0

Views: 13314

Answers (1)

Shane Haw
Shane Haw

Reputation: 723

What I mean is try something like this:

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 10; //End of first word
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 10);

richTextBox1.SelectionStart = 11; //Start of second word
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 20);

richTextBox1.SelectionStart = 21; //Next section to format
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 25);

which is just applying what is in this Question.

Upvotes: 1

Related Questions