Merge Rich Text? - c#

I have an application which involves building rich text character by character in order to undo it all at once. In order to retain that character's formatting, I select it and then can add the SelectedRtf property to my StringBuilder, however I want to be able to build each Rich Text character into one Rich Text string so that I can undo it in one go.
My question is how can you combine Rich Text strings into one big string while retaining all the formatting for each character.

merge it this way:
richTextBox2.Select(richTextBox2.TextLength, 0);
richTextBox2.SelectedRtf = richTextBox1.Rtf;

Related

C# textbox with mixed Western and Arabic text

I would like to display mixed western & arabic data read from a file into a text box.
An example of the data is I want to display is:
"You have", "يوجد لديك"
I read the data in as follows:
String tsIn = File.ReadAllText(tbxTSFileName.Text, Encoding.UTF8);
tbxBefore.Text = tsIn;
I cannot see any properties that let me set the textbox to "mixed" encoding.
When I open the file in Notepad++ I select Encoding>Character sets>Arabic>ISO 8859-6.
To make matters even more complicated, I would want to use the same textbox for other languages too, so the solution needs to work in all/most cases.
You need to show us the assignment to the textbox - for instance, is this a WinForms textbox, a WPF textbox or an HTML textbox.
Strings in C# are unicode - so can definitely hold Arabic.
You are reading UTF8 format which supports Arabic so I cannot tell what your actual problem is. Your tsIn could easily contain Arabic - is your problem that you cannot see Arabic in your WinForms TextBox ? This link has a lot of detail on displaying arabic on WinForms
Winforms Arabic Input text box

Highlight the differences in PDF using C#

I have generated the report in PDF format that compares two .DAT files and it works fine and it highlights entire rows which have differences. But now I want to highlight specific change.
Is there anyway that compares the text from pdf and highlights the differences between it???
This is the comparison in listview
This is the comparision in pdf file which highlight entire row but now I want to highlight specific change
I think you have to try character comparison,but not directly,i have done string comparison but using the replace and to lowercase method,i.e first replace space with "",and lower the strings,then you can go for character comparison,then only result would not be weird.

C# RichTextBox colored text

I've a RichTextBox and I want color text in it. Is there any tag option? I'd like something like this [color:red]nick[/color] some message. Because I need to save it as text and I want on reload have also colored text.
Can I do something like this without writing own method?
You can set color for text in RichTextBox with SelectionColor
And if you want to save your rtf as plain text, then you will have to look at rtf format. Example:
{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0;}
This line is the default color\line \cf2 This line is red\line \cf1
This line is the default color }
EDIT:
From this example - first of all you have to declare color table \colortbl in fololowing format:
{\colortbl; color1; color2; ... ; colorN;}
And then in the text you will have to enclose text with {\cfN YOUR_TEXT} where N is a number of color from table; you can not specify the boundaries of the block {}, then everything after \ cfN will be one color.
As the name says RichTextBox contains RichText
to change the Rtf text with 'rtf specific-tags' you can set/use the
RichTextBox.RtfProperty
also take a look at RichTextBox.SelectionColor to color text patterns in code
but when you don't want to use rtf, you said
need to save as text.
you could write your own 'markup' there is no built in expect rtf/html?
but rtf is text - at all
Example to use RichTextBix.SelectionColor to Color the text
richTextBox1.Text = "Hello";
richTextBox1.Select(0,2);
richTextBox1.SelectionColor = Color.Red;
colors the start of "Hello" red
and now you can access the 'taggeg' text in the RTFProperty of the RichTextBox
If you need examples of how things are encoded in RTF, you can create the document manually in Word or Wordpad, and save it as RTF. This will give you a hint about how to encode your formatting. Furthermore, if you're for instance creating help-documents, you can include them as an embedded resource and load them directly into the RichTextBox, with all the formatting included.
rtfMain.SaveFile(dlgSave.FileName);
From Reference Save text from rich text box with C#

C# + Windows Phone => TextBlock, preserve whitespaces?

I am creating an application where I need to loop through a series of text lines that may contain whitespace.
I build up a string by doing my_string += the_line_to_add and update the Text property of the TextBlock with the final string.
Pretty simple actually, however, a line that looks like this:
"a b c"
will end up as follows:
"a b c"
I don't want all of those spaces to be removed though. I want the line to keep the extra spaces and remain unchanged:
"a b c"
The TextBlock is created programmatically and added into a StackPanel. I looked at the different properties but just can't figure it out.
Honestly, I'd approach this problem differently. I wouldn't use whitespaces in a string to layout the text. If you need 3 string in the screen add 3 textboxes and set Margin proprety. This depends on the input text, but if there will be too many whitespaces the text will be out of the screen.
Alternatively, you can use Run to format the text.

Crystal Reports messing up Rich Text

I have a string that gets saved as rich text to a SQL field, so it has a lot of symbols in front of it like so...
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Verdana;}}
{\colortbl ;\red0\green0\blue255;}
\viewkind4\uc1\pard\sa200\sl276\slmult1\f0\fs22 Blah Blah Blah \par
I'm passing in this to Crystal Reports 11.5 as a parameter field, so the data type is string. I'm then just displaying it straight up by dragging the parameter to the report. The interpretation is set to RTF also in the paragraph tab of the formatting settings for this.
My problem is, it is removing the formatting tags but it is screwing up the text. It is randomly garbling words and inserting characters like the letter 'i' randomly in words, it's also putting some random letters in the background behind other words, making it look like it's been typed over manually if that makes sense, just makes the word look unreadable and bolded like someone typed over it with a typewriter.
I tried setting a new text object and then putting the rich text parameter in that to display, but then it doesn't remove/do any of the rich text formatting tags.
What gives? It can obviously do rich text as it removes the tags, but what is the deal with the random i's inserted into words and a couple of instances of the jumbled text over other words?
Unfortunately, I haven't used 11.5 yet.. but give this a try..
Format Field > Paragraph tab > Text Interpretation > RTF text
If the text is getting overlapped, then you can replace the following control set from your RTF text. It should work properly and not overlap.
data = data.Replace(#"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Verdana;}} {\colortbl ;\red0\green0\blue255;} \viewkind4\uc1\pard\sa200\sl276\slmult1\f0\fs22 Blah Blah Blah \par", string.Empty);

Categories