How to enable textBox to display Asian letter(Korea, Japanese, Chinese, Thailand, etc.)?
-
Tuesday, February 05, 2008 3:23 AM
I am making a text editor. How to enable textBox to display Asian characters(Korea, Japanese, Chinese, Thailand, etc.) input?
So if I load a text file with those Asian characters, the textBox must be able to display them well.
Mine is messy.
For input, there is no problem. It works well. But the problem is when I load it.
Thank you very much.
All Replies
-
Sunday, February 10, 2008 9:27 AM
By default the encoding of the .txt file is ANSI, and the StreamReader object uses the UTF-8 encoding to read the file content, thus results in the messy of the display in the TextBox, you can take either or the following two ways to workaround it:
1). Save your .txt file with UTF-8 encoding.
2). Keep the .txt file with default ANSI encoding, and use ANSI encoding to load the text file content, something like this:Code Snippet
using (StreamReader sr = newStreamReader(@"c:\test2\a.txt", System.Text.Encoding.Default)) //the default is ANSI
{
this.textBox1.Text = sr.ReadLine();
}
-
Monday, February 11, 2008 12:04 AM
There are other problems which are:
1. If user open non UTF-8(standard ANSI) text file, how to convert the encoding?
2. In this application, user can open a file, edit the content and save them back..but this application does not support creating and saving as a new file..
I just need to display Japanese Kanji, Katakana and Hiragana, the others are optional..so EVERYTIME user edit and save it back, I must set the file encoding to UTF-8 before saving it? Or how?
Do I also need to set the FONT since the font for Asian character is different? How to set the FONT if I want to display Japanese characters?
Is it possible to use the File::WriteAllText / File::ReadAllText instead of StreamWriter / StreamReader?
Thank you very much..
-
Monday, February 11, 2008 2:08 AMHaven't you read my solution #2 in my above post?? Please read it!
-
Monday, February 11, 2008 4:26 AM
Ye, I am sorry..I've tried it but I thought it did not work. I was load wrong file. Your code is working..But I want to know how to write back user edit? Just use the StreamWriter(fileName, System::Text::Encoding:
efault); ? Or how?Thank you very much..
-
Monday, February 11, 2008 4:28 AM
Yes. Have a try please.
-
Monday, February 11, 2008 6:00 AM
Thank you very much..


