c# - RichTextBox 粗体文本
问题描述
我正在填写richtextbox
从文本框收集的信息。我需要来自用户的输入在 Richtextbox 中变为粗体。我在 SO 中尝试了不同的答案,但是或者我做错了什么,或者我找不到正确的答案。
我试过 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.";
解决方案
以下是如何将句子的一部分(几个词)加粗:
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);
推荐阅读
- javascript - 如何返回 Mongoose 嵌套的对象数组
- angular - Ionic:如何强制以编程方式从 DOM 中“弹出”页面(无需按下 UI 后退按钮)
- django-tables2 - django-tables2:linkify,如何使目标新窗口
- cryptography - 如何在 ECC 曲线上找到最佳或足够好的基点 (G)
- python - 在 Django 中重定向给出 302 响应
- linux - docker start 从检查点映像失败
- javascript - 将时间戳数据解析为本地日期和时间的问题
- python - 使用分组卷积进行重复卷积的反向传播
- javascript - 如何正确地将元素滚动到始终有效的视图中?
- excel - 使用 Excel VBA 从单元格区域中隐藏空行的最快方法