V
V
Valery Smolsky2017-03-29 02:52:40
C++ / C#
Valery Smolsky, 2017-03-29 02:52:40

WInForm C++\CLI VS2013 Read text from file and output it to textbox?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {   
Stream^ myStream;
    openFileDialog1->Filter = "Текстовые файлы (*.txt)|*.txt|Все файлы (*.*)|*.*";

    if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
        label1->Text = openFileDialog1->FileName;
         if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
     {
        // Insert code to read the stream here.
        myStream->Close();
           textbox1->text=Convert::ToString(myStream);

     }

    }

}

Good afternoon, I can’t quite figure out how to read text from a file and write it to textbox, I tried to use the example from msdn, but apparently I don’t quite understand how it works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2017-03-29
@smolskiy94

label1->Text = System::IO::File::ReadAllText(openFileDialog1->FileName);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question