-1

When I select text by mouse in richTextBox and change its font this line works correctly:

 Font NewFont = new Font(toolStripComboBox1.SelectedItem.ToString(), GetCurrentDocument.SelectionFont.Size, GetCurrentDocument.SelectionFont.Style);

But when selecting text by ctrl+a then edit it, I get an error that object reference not set to an instance of an object. How to get the text I selected by ctrl+a?

2 Answers2

1

I think that problem is in fact that when you select whole content of RichTextBox, the selection contains more than one font and then the SelectionFont property is null, as is written on MSDN (in Remarks section).

How to change font family while preserving other formatting is described here: https://stackoverflow.com/a/26957748/7710314

Community
  • 1
  • 1
Kordik
  • 27
  • 2
-1

Try it;

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A && e.Control)
{
    textBox1.SelectAll();
}
}
alican akyol
  • 303
  • 3
  • 14