Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It need to display one word in one font and next line other font .
In Given sample program the last set font is applied for the entire text

What I have tried:

RichTextBox.Font = new Font("Arial", 14, FontStyle.Bold);
           RichTextBox.Text = Form1.FN+" "+Form1.LN+"\n";
           RichTextBox.Font = new Font("Arial", 10);
           RichTextBox.Text +=("Mobile: " )+ Form1.M;
Posted
Updated 22-Sep-18 5:58am

1 solution

You might want to read the documentation on the RichTextBox control[^]. There, you'll find various properties beginning with "Selection". Use the SelectionStart and SelectionLength properties where you can select text and then use the other properties to make changes to the selected text, such as SelectionFont.
 
Share this answer
 
Comments
49R 22-Sep-18 12:35pm    
RichTextBox.SelectionFont = new Font("Arial", 14, FontStyle.Bold);
RichTextBox.AppendText(Form1.FN + " " + Form1.LN + "\n");
RichTextBox.SelectionFont = new Font("Arial", 10);
RichTextBox.AppendText("Mobile: " + Form1.M);

got it Thank you
Dave Kreskowiak 22-Sep-18 13:24pm    
Great. You have now a much bigger problem.

You're creating new Font objects every time this code runs. Font object hold onto unmannaged, and limited, GDI resources. You never dispose of these created objects, but you created them without any upper limit. This means your code leaks resources and will, if done enough, will crash Windows.

Create your Font objects at the class level and you can reuse them, over and over, without creating new ones. Then, when your app exists, you can call Dispose on those Font objects and properly release the resources they are holding onto.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900