I wanted to write a simple notebook. I read the text from the file using openFileDialog and send it to the richTextBox. How to make it read Cyrillic correctly? I get current at the output:
- Uh ... How do you manage to read a file using OpenFileDialog? Show your code. Vanguyu unspecified encoding. - VladD
- That is, I open the file through it and read with StramReader - Ted
|
1 answer
Here I decided, at the beginning you need to register
System::Text::Encoding^ code = System::Text::Encoding::GetEncoding(1251); And specify the encoding through the code directly when reading. In general, it will look like this:
private: System::Void openToolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) { System::Text::Encoding^ code = System::Text::Encoding::GetEncoding(1251); if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { System::IO::StreamReader ^ sr = gcnew System::IO::StreamReader(openFileDialog1->FileName, code); richTextBox1->Text = sr->ReadToEnd(); sr->Close(); } }
|