【发布时间】:2011-04-28 14:30:58
【问题描述】:
我第一次使用托管 C++... 我使用 Winform 制作了一个表单,该表单有一个按钮可以浏览文件目录以及用户选择的任何路径,该路径应该在文本框中可见。
我想知道如何在托管 C++ 中创建文件浏览器对话框。
如果需要,附上表格的图像。
【问题讨论】:
标签: winforms visual-c++ managed
我第一次使用托管 C++... 我使用 Winform 制作了一个表单,该表单有一个按钮可以浏览文件目录以及用户选择的任何路径,该路径应该在文本框中可见。
我想知道如何在托管 C++ 中创建文件浏览器对话框。
如果需要,附上表格的图像。
【问题讨论】:
标签: winforms visual-c++ managed
您正在寻找OpenFileDialog 或SaveFileDialog。
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();
}
}
}
【讨论】: