How Can I format text in Rich Text Box like the following
02/11/2010 - 05:15 PM - Adam: Another test notes added on 2nd November
02/11/2010 - 05:14 PM - Z_kas: Test Notes. STAGE CHANGED TO: N Enq - Send Quote
02/11/2010 - 05:12 PM - user32: Another test notes added on 2nd November
Thanks
as stated by others there is a possible duplication with an earlier question. However, please see a code snippet below. You don’t have to get the length of the text you append in order to change its formatting, just set the format before you append. This (i think) gives better performance if you have a lot of text in the textbox.
This will work as long as there are no selections in the textbox by the user, then strange things will happen that I cannot explain. Perhaps someone else can enlighten us? The same problem appears with the solution proposed in Change color of text within a WinForms RichTextBox. I replaced the “:” you had after the user name just to get my code sample to work more easily with the DateTime thing, this can be easily modified in the “Split”.
And the call:
An alternative is to use the rtf format:
see msdn: http://msdn.microsoft.com/en-us/library/aa287595%28v=vs.71%29.aspx http://msdn.microsoft.com/en-us/library/aa140301.aspx#rtfspec_8
"\b " starts the bold section of text and "\b0" ends it. "\par" starts new paragraph/line (closest to \n).