Visual Basic richtextbox - 将特定文本设置为斜体字体样式
我创建了一个 Richtextbox,它根据用户输入的变量以及一些基本格式生成文本 - 例如:
name = txtname.text
richtextbox1.text = "Hello my name is " & name & "."
我想要做的是在显示时将名称变量中的文本设置为斜体,如下所示。
你好,我的名字是鲍勃。
我能找到的最好的办法是与选择范围有关,但对此没有任何运气。
干杯!
I have created a Richtextbox, which produces text based on user-inputted variables as well as some basic formatting - eg:
name = txtname.text
richtextbox1.text = "Hello my name is " & name & "."
What i want to do is set the text in the name variable in Italics when it is displayed, like this.
Hello my name is Bob.
Best I've been able to find is to do with selection ranges, but not had any luck with that.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
如果您使用写字板编写一些示例文本,将其保存为 rtf 格式,然后在记事本中打开该文件,您将得到一些开始。您可以删除写字板添加的一些内容(例如生成它的程序),但看起来您必须至少保留代码页和至少一种字体。
Try this:
If you use wordpad to write some sample text, save it in rtf format and then open the file in notepad, you will get something to start with. You can remove some of what wordpad adds (like the program that generated it) but it looks like you have to leave in at least the code page and at least one font.
希望这有帮助
Hope this helps
我编写了一个执行此操作的小例程:
因此,您将创建文本,然后调用
changeRTF("Bob",richtextbox1,color.gold,true)
。这段代码的唯一问题是它目前只能找到您正在查找的字符串的第一个存在。我用它来突出显示标题,所以到目前为止这还不是问题(我不重复标题)。
I wrote a little routine that does this:
So, you would create your text, and then call
changeRTF("Bob",richtextbox1,color.gold,true)
.The only problem with this code is it currently only finds the first existence of the string you are looking for. I use it to highlight titles so it hasn't been a problem so far (I don't repeat the titles).