作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 C# 使用 Visual Studio Express 2012。
我正在使用代码将文本添加到 RichTextBox
。每次添加 2 行。第一行要加粗,第二行要正常。
这是我唯一能想到的尝试,尽管我确信它不会起作用:
this.notes_pnl.Font = new Font(this.notes_pnl.Font, FontStyle.Bold);
this.notes_pnl.Text += tn.date.ToString("MM/dd/yy H:mm:ss") + Environment.NewLine;
this.notes_pnl.Font = new Font(this.notes_pnl.Font, FontStyle.Regular);
this.notes_pnl.Text += tn.text + Environment.NewLine + Environment.NewLine;
如何将粗体行添加到富文本框?
感谢您到目前为止提交的答案。我想我需要澄清一点。我没有添加这 2 行 1 次。我将多次添加这些行。
最佳答案
为了使文本加粗,您只需要用 \b
包围文本并使用 Rtf
成员。
this.notes_pln.Rtf = @"{\rtf1\ansi this word is \b bold \b0 }";
OP 提到他们将随着时间的推移添加线路。如果是这种情况,那么可以将其抽象为一个类
class RtfBuilder {
StringBuilder _builder = new StringBuilder();
public void AppendBold(string text) {
_builder.Append(@"\b ");
_builder.Append(text);
_builder.Append(@"\b0 ");
}
public void Append(string text) {
_builder.Append(text);
}
public void AppendLine(string text) {
_builder.Append(text);
_builder.Append(@"\line");
}
public string ToRtf() {
return @"{\rtf1\ansi " + _builder.ToString() + @" }";
}
}
关于c# - 如何在富文本框中添加粗体文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21211909/
下面是我用来制作 1px 文本描边轮廓的代码。但是如何使轮廓变粗呢?如果我只是用“5px”替换所有“1px”,结果看起来很疯狂。 HTML Hello! CSS .element { color:
我是一名优秀的程序员,十分优秀!