RichTextBox 粗体文本
RichTextBox bold text
我正在用从文本框中收集的信息填充 richtextbox
。我需要来自用户的输入在 Richtextbox 中变为粗体。我在 SO 中尝试了不同的答案,但是或者我做错了什么或者我找不到正确的答案。
我试过 RTF 和附加文本:
rtbGeneratedText.Text += @"In answer to your request regarding " +
rtbSpecialRequest.Text +
" for your booking " +
bookingNumberTxt.Text +
" the hotel has informed us that unfortunately it is not possible." + "\r\n" +
"Please let us know if this negative answer will affect your reservation in any way.";
这里是如何加粗句子的一部分(几个字):
string target = "the hotel has informed us that unfortunately it is not possible";
RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(target);
RichTextBox1.SelectionLength = target.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);
或者如果你想加粗所有文本:
RichTextBox1.SelectionStart = 0;
RichTextBox1.SelectionLength = RichTextBox1.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);
我正在用从文本框中收集的信息填充 richtextbox
。我需要来自用户的输入在 Richtextbox 中变为粗体。我在 SO 中尝试了不同的答案,但是或者我做错了什么或者我找不到正确的答案。
我试过 RTF 和附加文本:
rtbGeneratedText.Text += @"In answer to your request regarding " +
rtbSpecialRequest.Text +
" for your booking " +
bookingNumberTxt.Text +
" the hotel has informed us that unfortunately it is not possible." + "\r\n" +
"Please let us know if this negative answer will affect your reservation in any way.";
这里是如何加粗句子的一部分(几个字):
string target = "the hotel has informed us that unfortunately it is not possible";
RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(target);
RichTextBox1.SelectionLength = target.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);
或者如果你想加粗所有文本:
RichTextBox1.SelectionStart = 0;
RichTextBox1.SelectionLength = RichTextBox1.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);