我想打开一个对话框来搜索文件路径,而没有创建文件,只保存文本框中的路径文件。
这是我已经得到的,但它创建了一个新文件:
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
{
textBox->Text = saveFileDialog1->FileName;
myStream->Close();
}
}
答案 0 :(得分:0)
调用OpenFile是创建文件的原因。不要这样做。
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
textBox->Text = saveFileDialog1->FileName;
}