Richtexbox格式偶尔不会发生 [英] Richtexbox format doesn't happen occasionally

查看:100
本文介绍了Richtexbox格式偶尔不会发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了以下Subs,将文本放入带有

特定字体和颜色的richtextbox中,具体取决于上下文。偶尔,字体只是

没有得到应用,文本显示在默认样式中,而不是我已在变量中定义的

...


''将传入的文本发送到显示器。

Private Sub DisplayIn(ByVal text as String)

rtbDisplay.SelectionColor = uInColor

rtbDisplay.SelectionFont = uInStyle

rtbDisplay.AppendText(text)

End Sub


''将外发文本发送到显示器。

Private Sub DisplayOut(ByVal text As String)

rtbDisplay.SelectionColor = uOutColor

rtbDisplay.SelectionFont = uOutStyle

rtbDisplay.AppendText(text)

End Sub


....还有更好/更简单的方式将字体样式和颜色应用于富文本框中的特定

文本?

I have the following Subs defined to place text into a richtextbox with a
specific font and colour, depending on context. Occasionally, the font just
doesn''t get applied and the text appears in the default style and not the
one I''ve defined in the variables...

''Send incoming text to the display.
Private Sub DisplayIn(ByVal text As String)
rtbDisplay.SelectionColor = uInColor
rtbDisplay.SelectionFont = uInStyle
rtbDisplay.AppendText(text)
End Sub

''Send outgoing text to the display.
Private Sub DisplayOut(ByVal text As String)
rtbDisplay.SelectionColor = uOutColor
rtbDisplay.SelectionFont = uOutStyle
rtbDisplay.AppendText(text)
End Sub

....is there a better/easier way to apply a font style and colour to specific
text in a rich textbox?

推荐答案

Noozer,


为richtextbox控件设置SelectionFont时,它适用于

选择(选定文本)。因为在你的代码中你没有选择任何东西,

它一直不起作用。为了确保它将你的字体应用到

附加文本,请按照以下方式选择文本,然后设置

相应的属性:

Dim PositionbeforeAppend As Integer = Me.RichTextBox1.TextLength


Me.RichTextBox1.AppendText(vbCrLf&" This is new Text。"& vbCrLf)< br $>
RichTextBox1.SelectionStart = PositionbeforeAppend

Me.RichTextBox1.SelectionLength = Me.RichTextBox1.TextLength -

PositionbeforeAppend


RichTextBox1.SelectionFont = New Font(" Arial",16,FontStyle.Bold)

RichTextBox1.SelectionColor = Color.Blue

希望这会有所帮助!

Bharat Patel

Microsoft,Visual Basic .NET

此帖子按原样提供。没有保证,也没有授予任何权利。

请仅回复新闻组。谢谢。

Noozer,

When you set SelectionFont for the richtextbox control, it applies to the
selection (selected Text). Since in your code you are not selecting anything,
it does not work all the times. To make sure it applies your fonts to the
appended text, select the text after appending it as follows and then set the
appropriate properties:

Dim PositionbeforeAppend As Integer = Me.RichTextBox1.TextLength

Me.RichTextBox1.AppendText(vbCrLf & "This is new Text." & vbCrLf)
RichTextBox1.SelectionStart = PositionbeforeAppend
Me.RichTextBox1.SelectionLength = Me.RichTextBox1.TextLength -
PositionbeforeAppend

RichTextBox1.SelectionFont = New Font("Arial", 16, FontStyle.Bold)
RichTextBox1.SelectionColor = Color.Blue
Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.




" Bharat Patel [MSFT]" < BH ***** @ online.microsoft.com>在消息中写道

新闻:Jn ************** @ cpmsftngxa07.phx.gbl ...

"Bharat Patel [MSFT]" <bh*****@online.microsoft.com> wrote in message
news:Jn**************@cpmsftngxa07.phx.gbl...
Noozer,
为richtextbox控件设置SelectionFont时,它适用于
选择(选定的文本)。因为在你的代码中你没有选择
任何东西,所以它不会一直有效。为确保将字体应用于
附加文本,请按照以下方式选择文本,然后将
设置为相应的属性:
Noozer,

When you set SelectionFont for the richtextbox control, it applies to the
selection (selected Text). Since in your code you are not selecting anything, it does not work all the times. To make sure it applies your fonts to the
appended text, select the text after appending it as follows and then set the appropriate properties:




我实际上弄明白昨晚是什么...


既然你不能设置RichTextBox的最大大小,我就抓住了

从包装盒中取出文本,将其剪裁下来并重新涂抹。这将失去它持有的任何

格式。这一切都发生得如此之快以至于我没有抓住它




现在我需要一种方法将richtextbox设置为特定大小( 4000个字符

max,例如)


Thx!



I actually figured out what it was last night...

Since you can''t set the maximum size of a RichTextBox, I was grabbing the
text from the box, trimming it down, and reapplying it. This would lose any
formatting that it held. It all happened so fast that I didn''t catch it
right away.

Now I need a way to set a richtextbox to a specific size (4000 characters
max, for example)

Thx!


您可以设置MaxLength属性希望这会有所帮助!

Bharat Patel

Microsoft,Visual Basic .NET


此帖子按原样提供。没有保证,也没有授予任何权利。

请仅回复新闻组。谢谢。

You can set the MaxLength property of the RichTextbox to the desired value.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.


这篇关于Richtexbox格式偶尔不会发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆