AllTheTimeWorld.com

csharp richtextChange font of selected text.

Change font of selected text.

Uses the Font Dialog to select font

Change font of selected text.

Uses the Font Dialog to select font

Continue with the Notes Application.

Next we will write the code to change the font of the selected text.

Add a button to the toolbar and name it toolStripFont. Download this image to use for the button:
If you wish, you can add a menu item for the font also.

.

Write the code shown below:

private void toolStripFont_Click(object sender, EventArgs e)
{
   // You can also add a font item to  the menu under tools.
   SelectFont();
}

private void SelectFont()
{
   // Display the font dialog and change font of selected text.
   // If no text is selected this has no effect.
   Font selectionFont = richTextBox1.SelectionFont;
   fontDialog1.Font = richTextBox1.SelectionFont;
   fontDialog1.ShowDialog();
   richTextBox1.SelectionFont = fontDialog1.Font;
}

Click Save All at this point and run the program.