【问题标题】:C# Use different font size on a line in richtextboxC#在richtextbox的一行上使用不同的字体大小
【发布时间】:2013-08-15 16:43:50
【问题描述】:

我们如何在RichTextBox 的一行上使用不同的字体大小?假设我希望第一个单词是字体 10,但同一行上的第二个单词我希望它是 20。我正在使用以下内容:

    private void textBox10_TextChanged(object sender, EventArgs e)
    {
        richTextBox2.Font = new Font("Microsoft San Serif", 12);
        richTextBox2.Text = "\n\n" + textBox10.Text;         
    }

但它适用于该行的整个文本...

【问题讨论】:

  • 你试过什么?您是否甚至寻找过实现这一目标的方法,因为我可以在相关问题中看到很多您的问题的答案?
  • 我已经编辑了我的答案@Matten。
  • 看看stackoverflow.com/questions/15554401/… 将选择设置为第一个单词更改字体,将选择设置为下一个工作更改字体等...
  • 网站中的例子适用于整个richtextbox..
  • 了解段落和运行。我认为这应该对你有所帮助。你可以在同一个段落中使用两个不同的 Runs,但是两个不同的 Runs 可以有不同的字体大小等等。

标签: c# richtextbox


【解决方案1】:

我的意思是尝试这样的事情:

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 10; //End of first word
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 10);

richTextBox1.SelectionStart = 11; //Start of second word
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 20);

richTextBox1.SelectionStart = 21; //Next section to format
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new System.Drawing.Font("Tahoma", 25);

这只是应用 this Question 中的内容。

【讨论】:

  • 如果客户端机器中没有“Tahoma”字体会怎样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-04
  • 1970-01-01
  • 1970-01-01
  • 2011-11-16
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多