使用winforms和Managed C++浏览文件对话框

tec*_*ner 4 managed visual-c++ winforms

我是第一次使用Managed C++ ...我使用Winform创建了一个表单,它有一个按钮来浏览目录中的文件以及用户选择的路径,该路径应该在文本框中可见.

我想知道如何在托管C++中创建文件浏览器对话框.

如果需要,附加表单的图像. 在此输入图像描述

mse*_*ant 5

您正在寻找OpenFileDialogSaveFileDialog.

void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
       {
          Stream^ myStream;
          OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

          openFileDialog1->InitialDirectory = "c:\\";
          openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
          openFileDialog1->FilterIndex = 2;
          openFileDialog1->RestoreDirectory = true;

          if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
          {
             if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
             {
                // Insert code to read the stream here.
                myStream->Close();
             }
          }
       }
Run Code Online (Sandbox Code Playgroud)