PC Review


Reply
Thread Tools Rating: Thread Rating: 8 votes, 4.75 average.

Append RTF text in a RichTextBox

 
 
Olivier
Guest
Posts: n/a
 
      26th Nov 2003
Hi

How can I append RTF formated text in a RichTextBox ?

Thanks

Olivier
 
Reply With Quote
 
 
 
 
Dino Chiesa [Microsoft]
Guest
Posts: n/a
 
      27th Nov 2003
rtb.AppendText() ??

"Olivier" <(E-Mail Removed)> wrote in message
news:754401c3b42c$50752100$(E-Mail Removed)...
> Hi
>
> How can I append RTF formated text in a RichTextBox ?
>
> Thanks
>
> Olivier



 
Reply With Quote
 
 
 
 
Olivier
Guest
Posts: n/a
 
      27th Nov 2003

The AppendText() method can only add text (not rtf
formated text !)



>-----Original Message-----
>rtb.AppendText() ??
>
>"Olivier" <(E-Mail Removed)> wrote in

message
>news:754401c3b42c$50752100$(E-Mail Removed)...
>> Hi
>>
>> How can I append RTF formated text in a RichTextBox ?
>>
>> Thanks
>>
>> Olivier

>
>
>.
>

 
Reply With Quote
 
Dino Chiesa [Microsoft]
Guest
Posts: n/a
 
      1st Dec 2003
Ahh, I see. Maybe you want to set the Rtf property?

ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemWindowsFormsRichTextB
oxClassRtfTopic.htm
http://msdn.microsoft.com/library/en...ssRtfTopic.asp
http://www.devhood.com/messages/mess...hread_id=91124

To append, I would assume just doing
rtb.Rtf += RtfToAppend;

would work.

If you do not have the actual RTF text, then this may be an easier way: you
can apply formats to the text, then append the text, then unapply the
formats.

For example, you can do this to turn on boldface:
System.Drawing.Font currentFont = this.richTextBox1.SelectionFont;
this.richTextBox1.SelectionFont = new Font(
currentFont.FontFamily,
currentFont.Size,
FontStyle.Bold
);
this.richTextBox1.AppendText("This text appears in bold");


Then as you append text, it is bolded.
You can apply the same approach to turn on Italic, bullets, indentation,
etc.

For colors, it is similar:
this.richTextBox1.SelectionColor =
System.Drawing.Color.FromName("Green");
this.richTextBox1.AppendText("This text appears in green");

this.richTextBox1.SelectionColor =
System.Drawing.Color.FromName("Black");



"Olivier" <(E-Mail Removed)> wrote in message
news:08ec01c3b4c1$191a2ee0$(E-Mail Removed)...
>
> The AppendText() method can only add text (not rtf
> formated text !)
>
>
>
> >-----Original Message-----
> >rtb.AppendText() ??
> >
> >"Olivier" <(E-Mail Removed)> wrote in

> message
> >news:754401c3b42c$50752100$(E-Mail Removed)...
> >> Hi
> >>
> >> How can I append RTF formated text in a RichTextBox ?
> >>
> >> Thanks
> >>
> >> Olivier

> >
> >
> >.
> >



 
Reply With Quote
 
New Member
Join Date: Feb 2007
Posts: 1
 
      10th Feb 2007
RichTextBox1.SelectedRtf = RtfContentString;
 
Reply With Quote
 
New Member
Join Date: Apr 2012
Posts: 1
 
      24th Apr 2012
I had to address the same problem today. I found this workaround. Basically, let Windows to the work for you by copying and pasting into a temporary Rich Text Box. This example copies the contents of RichTextBox1 and RichTextBox 2 to the clipboard. (Vb.net 2003)
Code:
    Public Sub copyText()
            Dim rtbTmp As New RichTextBox ' Temporary Rich Text Box
            Dim datobj As New System.Windows.Forms.DataObject

            ' Copy RichTextBox1 into rtbTmp
            rtbTmp.Rtf = RichTextBox1.Rtf
            ' Add Line Feed (if you want one)
            rtbTmp.AppendText(vbCrLf)  
            ' Copy RichTextBox2 to the Clipboard
            datobj.SetData(DataFormats.Rtf, RichTextBox2.Rtf) 
            Clipboard.SetDataObject(datobj)
            ' Paste RichTextBox2's copied text to the end of Temporary Rich Text Box
            rtbTmp.SelectionStart = rtbTmp.TextLength
            rtbTmp.Paste()
            ' Copy combined contents of Temporary Rich Text Box to the clipboard
            datobj.SetData(DataFormats.Rtf, rtbTmp.Rtf)
            Clipboard.SetDataObject(datobj)
    End Sub

Last edited by Craigers; 24th Apr 2012 at 05:48 PM..
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Setting RichTextBox.SeletcionStart Change RichTextBox.Text ?!?!? eBob.com Microsoft VB .NET 1 30th Jul 2007 05:51 AM
Append rtf content to a richtextbox Fab Microsoft C# .NET 1 30th Nov 2006 01:29 PM
how to load a rtf into a richtextbox at runtime (the rtf file provided in app)? Henry J. Microsoft C# .NET 2 4th May 2006 09:21 PM
Printing RTF Text from a RichTextBox Jeff Gaines Microsoft Dot NET Framework Forms 0 9th Aug 2003 02:06 PM
Read in RTF into a RichTextBox control and save it to a RTF file Yuelin Microsoft C# .NET 1 25th Jul 2003 04:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:50 AM.