Reputation: 3
I want to change font of a selected text in richtextbox called Notes
I tried with this code but it doesn't work
Notes.SelectionFont = FontStyle.Italic;
Can someone help me?
Upvotes: 0
Views: 334
Reputation: 48
Try this; Select a text then trigger
private void button1_Click(object sender, EventArgs e)
{
int selstart = richTextBox1.SelectionStart;
int sellength = richTextBox1.SelectionLength;
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
richTextBox1.SelectionStart = richTextBox1.SelectionStart + richTextBox1.SelectionLength;
richTextBox1.SelectionLength = 0;
richTextBox1.SelectionFont = richTextBox1.Font;
richTextBox1.Select(selstart, sellength);
}
Upvotes: 1