Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过ctrl+;C#Windows窗体中的a_C#_Winforms - Fatal编程技术网

通过ctrl+;C#Windows窗体中的a

通过ctrl+;C#Windows窗体中的a,c#,winforms,C#,Winforms,当我在richTextBox中用鼠标选择文本并更改其字体时,该行正常工作: Font NewFont = new Font(toolStripComboBox1.SelectedItem.ToString(), GetCurrentDocument.SelectionFont.Size, GetCurrentDocument.SelectionFont.Style); 但是当通过ctrl+a选择文本并对其进行编辑时,我得到一个错误,即对象引用未设置为对象的实例。如何获取我通过ctrl+a选择

当我在richTextBox中用鼠标选择文本并更改其字体时,该行正常工作:

 Font NewFont = new Font(toolStripComboBox1.SelectedItem.ToString(), GetCurrentDocument.SelectionFont.Size, GetCurrentDocument.SelectionFont.Style);
但是当通过
ctrl+a
选择文本并对其进行编辑时,我得到一个错误,即对象引用未设置为对象的实例。如何获取我通过
ctrl+a
选择的文本?

试试看

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A && e.Control)
{
    textBox1.SelectAll();
}
}

我认为问题在于,当您选择RichTextBox的全部内容时,所选内容包含多个字体,然后SelectionFont属性为空,如上所述(在备注部分)

下面介绍如何在保留其他格式的同时更改字体系列: