1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
// Titre
openFileDialog1->Title = "Chargement";
// Extension par défaut
openFileDialog1->DefaultExt = "txt";
// Filtre sur les fichiers
openFileDialog1->Filter = "Tous les fichiers (*.*)|*.*";
openFileDialog1->FilterIndex = 1;
// Ouverture boite de dialogue OpenFile
if (openFileDialog1->ShowDialog(this) == Windows::Forms::DialogResult::OK)
{
// On vide le TextBox
textBox1->Text = String::Empty;
// Ouverture du fichier sélectionné
// son nom est dans openFileDialog1->FileName
IO::StreamReader ^sr = gcnew IO::StreamReader(openFileDialog1->OpenFile(), System::Text::Encoding::Default);
try
{
textBox1->Text = sr->ReadToEnd();
}
finally
{
if (sr!=nullptr)
sr->Close();
}
}
} |