在设计状态下将RichTextBox控件的字体设置为“新宋体,9”,但在运行时,键入的新内容都会以Arial来显示,不知为何?向大家请教。

解决方案 »

  1.   

    richTextBox1.SelectionFont = new Font("Tahoma", 12, FontStyle.Bold);
    richTextBox1.SelectionColor = System.Drawing.Color.Red;这些属性只影响选定的文本,如果未选定文本,则只影响在当前插入点位置键入的文本
      

  2.   

    你保存richtextbox中的内容的时候,不要用text属性来存,而要通过rtf属性来存,参看
    http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp
      

  3.   

    @ lxhvc()
    我也是这么写的,但在键入新内容时,依然是arial字体。
      

  4.   

    to 我也是这么写的,但在键入新内容时,依然是arial字体。你应该设置Font属性和ForeColor属性,方法和设置SelectionFont和SelectionColor一样。
      

  5.   

    @ Knight94(愚翁)这个我也试过了,在一个form上,放一个RichTextBox控件,设置了Font和ForeColor属性,在运行时,只要键入内容,就是Arial字体的。
      

  6.   

    to 这个我也试过了,在一个form上,放一个RichTextBox控件,设置了Font和ForeColor属性,在运行时,只要键入内容,就是Arial字体的。不应该,如果你设置了richtextbox的Font和ForeColor属性,应该在输入的时候发生变化。而且我试了,没什么问题。
      

  7.   

    如果是动态去修改这个属性,来显示将要输入的字体和颜色,需要如下
    yourRichBox.Focus();
    yourRichBox.SelectionFont = new Font( "宋体", 14 );
    yourRichBox.SelectionColor = Color.Purple;
      

  8.   

    需要先选中修改的字符:
    public void SelectMyString()
     {
        // Create a string to search for the word "fox".
        String searchString = "fox";
        // Determine the starting location of the word "fox".
        int index = textBox1.Text.IndexOf(searchString, 16, 3);
        // Determine if the word has been found and select it if it was.
        if (index != -1)
        {
           // Select the string using the index and the length of the string.
           textBox1.Select(index, searchString.Length);
        }
     }
      

  9.   

    我将代码贴出来吧,很简单的:
    private void Form1_Load(object sender, EventArgs e)
    {
                richTextBox1.Focus();
                richTextBox1.SelectionFont = new Font("新宋体", 9);
                richTextBox1.SelectionColor = Color.Black;
    }在设计状态下,Font属性和ForeColor属性也是这么设置的。但运行时,只要输入新的内容,显示的字体就是arial,而不是我设置的,我在keydown事件中显示了richTextBox1.SelectionFont属性,验证了这一点。
      

  10.   

    @ lxhvc() 
    我的目的很简单,只是想让RichTextBox以我想要的字体显示我输入的内容。结果我新输入的内容都是以arial字体显示的。而在设计状态时输入的内容倒是和Font属性一致,这个算是bug吗?
      

  11.   

    你在
    richTextBox1.Focus();
    之前加上
    this.Show();