We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Insert Formatted RTF text in caret position

Thread ID:

Created:

Updated:

Platform:

Replies:

140755 Nov 5,2018 04:50 PM UTC Nov 7,2018 12:12 PM UTC WPF 3
loading
Tags: SfRichTextBoxAdv
Remigio Fattori
Asked On November 5, 2018 04:50 PM UTC

Hi,

i need to add in WPF SfRichTextBoxAdv, formatted RTF text in caret position. I found only how add simple text with:
richTextBoxAdv.Selection.InsertText("Hello World!!!");
Is that a way to add formatted RTF text?

Thank you!

Karthikeyan Chandrasekar [Syncfusion]
Replied On November 7, 2018 11:33 AM UTC

Hi Remigio, 
Currently SfRichTextBoxAdv doesn’t have API to insert formatted text. As a workaround, it can be achieved by creating formatted text as RTF and using paste command of SfRichTextBoxAdv.  
Step 1: Build RTF content for your formatted text. You can use DocIO library for this purpose. Kindly refer to UG link -https://help.syncfusion.com/file-formats/docio/overview 
Step 2: Set the RTF content in clipboard.  
Step 3: Invoke paste command.  
Code snippet:  
            SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();  
            //Build RTF content for your formatted text.  
            string formattedText = @"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\b\ltrch Hello world}\li0\ri0\sa0\sb0\fi0\ql\par}{\f2 {\i\ltrch Welcome to WPF}\li0\ri0\sa0\sb0\fi0\ql\par}}}";  
            //Set RTF text in clipboard with format.  
            Clipboard.SetText(formattedText, TextDataFormat.Rtf);  
           Button insertText = new Button();  
            //Invoke the paste command.  
            insertText.Click += (object sender, RoutedEventArgs e) => { SfRichTextBoxAdv.PasteCommand.Execute(null, richTextBoxAdv); };  
              
Regards, 
Karthikeyan  


Remigio Fattori
Replied On November 7, 2018 12:10 PM UTC

It works!

Thank you

Karthikeyan Chandrasekar [Syncfusion]
Replied On November 7, 2018 12:12 PM UTC

You are welcome Remigio. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon