Smith
Smith

Reputation: 5959

format text in richtextbox vb6

I need to format text to be outputted in a richtextbox, for example, just doing this in wordpad

Hello world

gives this in notepad when i opend the richtext document in notepad

{\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.

Is there a simple way to achieve this without manipulation the richtext format?

thanks

Upvotes: 0

Views: 4654

Answers (1)

GTG
GTG

Reputation: 4954

You can use the RichTextBox control itself to manipulate the contents, like this:

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. There are some RTF libraries out there, both for ActiveX and .NET.

Upvotes: 2

Related Questions