C# textbox with mixed Western and Arabic text - c#

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

Related

Insert a formatted footnote using Microsoft.Interop.Office.Word

I am trying to inset formatted footnotes into an open word document using a WinForms application.
While I am able to use Interop.Word to set plain text footnotes and so long as I use plain text it works fine. However, I also want the user to be able to paste rich text formatted text from a rich text box into the footnote. This never works and always shows the rich text codes.
I know that footnotes can take formatting because if I put the rich text int a clipboard and paste it into a footnote the formatting is preserved.
I have even tried putting the rich text into the clipboard and then setting the string (s) to the clipboard contents using "s = Clipboard.GetText(TextDataFormat.Rtf);" It seems as if this should be exactly what I am pasting, but if I paste into the footnote it works. If the program sets it using the code below it does not work.
I appreciate any help.
application = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
application.ActiveDocument.Footnotes.Add(application.Selection.Range, "", s);
Cindy's answer was helpful. I fixed the problem by doing the following:
Saving the current selected position in the document and current clipboard contents.
Inserting a blank footnote.
Selecting the footnote.
Putting the string into the clipboard as rich text format.
Sending/pasting the information from the clipboard to Word.
Restoring the clipboard and original selected position in the document.

Allow text from different cultures in Textbox C#

I have an application in which username is both in English and Japanese(for Japanese users.)
I am retrieving username from database and want to allow both English and Japanese cultures' username in my text box that displays username.
How to do it?
There is a property call ImeMode for text box which is by default "No control" which allow you to enter both English and Japanese
There is also other options like Hiragana,katagana,Alpha etc...
And regarding question of comparing string there is no need to worry about it is work with Unicode so it will compare both English and Japanese text.

Displaying Raw Data From Image File Using TextBox or RichTextBox?

My program reads a DDS image file and stores it as a byte array. I want to be able to show the users the raw data in a TextBox form so at first I convert the byte array to a string using the following code:
string data = System.Text.Encoding.ASCII.GetString(bytes);
I then set the TextBox text:
textBox.Text = data;
The problem I am having is the text box is not showing all the data. Here is a screenshot of how it looks:
As you can see only the first few characters are displayed. I am assuming this is because the string contains a null terminator which the TextBox interprets as the end of the string. Here is a copy paste of the first 50 or so characters in the string which I copied directly from the debugger watch window:
DDS |\0\0\0\a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
As you can see the first null character comes right after "DDS |" which explains why that's all that shows up in the TextBox.
What I want to be displayed is similar to what you see if you edit the raw DDS file with a text editor such as Notepadd++.
Opening the DDS file in Notepad++ produces the following:
My question is, how do I get my TextBox (or RichTextBox) to show the data in the same way that Notepad++ shows it?
The simplest solution is to use this:
textbox.Text = data.Replace("\0", #"\0");
This will force the textbox to actually show a backslash followed by a zero where the nulls would be. Alternatively, you could replace the nulls with some other character or string.

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);

How to display Chinese characters in ListView?

maybe anyone have ideas of how to display Chinese characters in the ListView control ?
Ensure you have Chinese character capabilities on your actual machine and browser:
http://www.jp41.com/internet-explorer/chinese/
If you've done that and it's still a problem, perhaps you are getting data from a database that has been input as Chinese, but the data type on the relevant column isn't Unicode. In which case make change the data type to for example, nvarchar.

Categories