简体   繁体   English

RichTextBox 粗体文本

[英]RichTextBox bold text

I am filling a richtextbox with information gathered from Textboxes.我正在用从文本框收集的信息填充richtextbox文本框。 I need that the input from the user gets Bold in the Richtextbox.我需要来自用户的输入在 Richtextbox 中变得粗体。 I have tried different answers in SO, but or either I am doing something wrong or I couldn't find the right answer to this.我在 SO 中尝试了不同的答案,但是或者我做错了什么,或者我找不到正确的答案。

I've tried RTF and appendtext:我试过 RTF 和 appendtext:

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.";

Here is how you can Bold a portion of the sentence (a few words):以下是如何将句子的一部分(几个单词)加粗

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);

Or if you want to Bold all the text:或者,如果您想加粗所有文本:

RichTextBox1.SelectionStart = 0;
RichTextBox1.SelectionLength = RichTextBox1.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM