Saving RTF on DataBase and loading it back into WinForms application - c#

I have a Windows Forms Application with a RichTextBox control. I want the user to write rich text on that control (with bold, changes of letter size and all that stuff), save that rich text on database, and then load it again on my Windows Forms application properly formatted.
The way I'm trying to do this, I save on a varchar field in my database the contain of RichTextBox.Rtf property, like this:
string richText = myRichTextBox.Rtf;
Then richText is saved on database exactly as is read on that line. To load the rich text back into winform, code is a little bit more tricky:
//Function that receives a string whit rich text and loads it into richTextBox
private void LoadRTF(string RTF)
{
MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(RTF));
myRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
} //LoadRTF
Problem is with this last code, when loading RTF from database is throwing an argument exception. Any idea why this is happening?

Turns out I was just not escaping some characters in SQL query. Now everything seems to work fine.

Related

UP simple Way to store/retrieve formatted Text

currently, I'm using Richeditbox in my to edit and display formatted text in App. there a now a lot of RichEditBoxes. because its the goal of the App, to show a list of formatted text blocks with different Content. The Performance is really slow and the space in DB is great, I'm storing the text in RTF-format in blobs.
What is the easiest way to show simple formatted Text (eg bold, italic)? I never found a quite sample?
If you just want to display formatted text you have two options.
RichTextBlock is a TextBlock-like counterpart of RichEditBox. It is however more performant as it just displays the content and does not offer editing.
Alternatively there is a MarkdownTextBlock control in the UWP Community Toolkit, which can display simple formatted text in the Markdown format.

TextBox display returns from RichTextBox?

I am creating an invoice program for a small local company but have run into sort of a problem. I have it setup so the invoice is printable by taking a screen shot of the application then remove all image detail so it is just the text from the Windows Form.
Problem is RichTextBoxes do not support drawing the text from them using DrawToBitmap. To fix this issue I am attempting to use a normal textbox. When inputting the address into a new textbox it does not show the returns in the text so it is all bunched up. Is there a way to fix this?
First all, I'll assume your TextBox's Multiline property is set to true.
This will work:
textBox1.Text = string.Join(Environment.NewLine, richTextBox1.Lines);
This code formats the text in your RichTextBox (in its Lines property) so your TextBox will display it properly.

How to display RTF text in to tinyMCE editor

I am using tinyMCE editor. I have rtf formatted string in database column which I want to show in the browser editor i.e. tinyMCE. So that, user will edit the text as he wants. But for that I found I need to convert the rtf string in to xml to see it, since my tinyMCE is showing xmls properly. I am able to show the text from rtf string but I misses out the formatting like bold text, red colored text, \n etc. I want to retain all this formatting. How shall I retain the formatting or how shall I display the rtf text with the formatting or how shall I convert rtf text in to xml properly? I want to display rtf text like I am saving it in some rtf file and opening that file in ms word or open office word that way I want to see the format. rtf is Rich Text format.
You should convert your RTF to HTML and use that for TinyMCE, here is a code project article that will get you started :
http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter

Format RTF text into multiple textboxes

I have a richtextbox on my wpf form that the user types into, with no restrictions on length. However, on my active reports output, I have pages with fixed-space textboxes on each page. Is there any way to figure out how much of the rich text will fit into a textbox, write it out, and then continue writing the rest on the next page until i run out of text to write?
You can measure the length of plain text on an ActiveReports Page using the Page object's MeasureText method. See the following documentation: http://www.datadynamics.com/help/activereports6/ActiveReports.Document~DataDynamics.ActiveReports.Document.Page~MeasureText.html
If you have RTF output (I'm not sure if you do or not based on the information provided) it is probably not feasible to manually measure the text and break it up simply because RTF text is complex and breaking into parts is more difficult. However, the RichEdit/RTF control in ActiveReports should be able to paginate/page break it fine if you can let that control grow.

put \\scaps in RTF for small caps

I'm using dynamic RichTextBox control in C# 2.0 and I want to insert "\scaps" in RTF so that if the file is saved programatically and then opened in MS-Word certain text be seen smallcaps.
Can anyone tell me the code as how to insert the tag?
Well, you can access the rich text directly through the Rtf property on the rich text box.

Categories

Resources