简体   繁体   English

在richtextbox vb6中格式化文本

[英]format text in richtextbox vb6

I need to format text to be outputted in a richtextbox, for example, just doing this in wordpad 我需要格式化文本以在richtextbox中输出,例如,在wordpad中执行此操作

Hello world 你好世界

gives this in notepad when i opend the richtext document in notepad 当我在记事本中打开richtext文档时,在记事本中给出了这个

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\i\f0\fs20 hello\i0  world\par
}

I want to format text incode, and display the formated text in richtextbox, just like the example i did in wordpad above. 我想格式化文本incode,并在richtextbox中显示格式化文本,就像我在上面的wordpad中所做的那样。

Is there a simple way to achieve this without manipulation the richtext format? 有没有一种简单的方法来实现这一点而无需操纵richtext格式?

thanks 谢谢

You can use the RichTextBox control itself to manipulate the contents, like this: 您可以使用RichTextBox控件本身来操作内容,如下所示:

RichTextBox1.Text = "Hello world"  'Set the text
RichTextBox1.SelStart = 0  'Select the first 5 characters
RichTextBox1.SelLength = 5
RichTextBox1.SelItalic = True 'Set the selection to italic

However, you need to know exactly the position of the text you want to format, so if you want to generate a dynamic document, this is difficult. 但是,您需要确切地知道要格式化的文本的位置,因此如果要生成动态文档,则很难。 This seems designed for you to be able to put formatting buttons on your form and let the user format the text he is looking at by selecting portion of it and choose format. 这似乎是为了让您能够在表单上放置格式按钮,让用户通过选择部分格式并选择格式来格式化他正在查看的文本。 If you want to create dynamic documents you'll probably want to use a library to generate the RTF document and display the results. 如果要创建动态文档,您可能希望使用库来生成RTF文档并显示结果。 There are some RTF libraries out there, both for ActiveX and .NET. 有一些RTF库,包括ActiveX和.NET。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM