【问题标题】:Add partially bolded text to a richtextbox in vb.net在 vb.net 中将部分粗体文本添加到富文本框中
【发布时间】:2020-11-19 23:02:59
【问题描述】:

我正在使用富文本框作为我的程序的显示日志。该程序将一个目录从源机器大量复制到多台目标机器。我希望在添加行时将添加到文本框中的计算机名称加粗。我目前添加的行如下:

rtbStatusLog.AppendText(My.Computer.Clock.LocalTime.ToString + " " + TargetName + ": File Copied: " + destinationFileName + vbCrLf)

我需要“目标名称”变量和后续的:加粗,但没有别的。

我也希望这样做,因为如果可能会添加行,而不是在最后选择结果并将它们加粗。

【问题讨论】:

标签: vb.net richtextbox


【解决方案1】:

富文本框有一个名为SelectionFont 的属性。设置此属性的属性会改变文本的显示方式。

所以这样做:

Dim currentFont As System.Drawing.Font = rtbStatusLog.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle

rtbStatusLog.SelectedText = My.Computer.Clock.LocalTime.ToString
rtbStatusLog.SelectionFont = New Font(currentFont.FontFamily,currentFont.Size,newFontStyle) 
rtbStatusLog.SelectedText = " " + TargetName + ": File Copied: " + destinationFileName + vbCrLf)

当您更改 SelectedText 属性时,您实际上是在向该框写入内容。

Reference SelectedText

Reference SelectionFont

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2013-11-06
    相关资源
    最近更新 更多