可以使用一個標志變量來記錄是否已經(jīng)彈出過SaveFileDialog窗口,如果已經(jīng)彈出過,則不再彈出。示例如下:
bool saveDialogShown = false;
private void btnSave_Click(object sender, EventArgs e)
{
if (!saveDialogShown)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Save file logic here
}
saveDialogShown = true;
}
}