问题描述
使用Windows窗体应用程序
Using Windows Forms Application
使用C#
使用saveDialog
Using saveDialog
问题:
如果我为已存在的文件单击保存"按钮时不希望看到saveDialog,该怎么办?
What if I do not want to see a saveDialog when I click a Save Button for a file that already exists?
如果我为不存在的文件单击保存"按钮时只想看到saveDialog,该怎么办?
What if I only want to see saveDialog when I click a Save Button for a file that does not exist?
msdn仅引入可处理SaveAs(创建新文件)的saveDialog,而不会保存(将更改保存到文件).
msdn only introduces saveDialog that handles SaveAs (creates new file), but not Save (saves changes to file).
我强烈希望我的问题足够清楚
I strongly hope my questions are clear enough
感谢您为此付出的宝贵时间.
and I thank you for spending your valuable time on this.
我是Chieki先生(从香港写信)
I am Mr. Chieki (writing from Hong Kong)
推荐答案
谢谢你在这里摆姿势.
对于您的问题,请尝试以下代码.我尝试过这个.效果很好.
For your question, please try the following code. I tried it. It works well.
在设计器中.
这是代码.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace saveDialog
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.FileName = textBox1.Text;
if (!File.Exists(saveFileDialog1.FileName))
{
// When user clicks button, show the dialog.
saveFileDialog1.ShowDialog();
}
}
}
}
在我的计算机上,存在123.txt.
In my computer there is 123.txt exist.
当我输入123.txt之类的文件名时,没有保存对话框出现.
When I input filename like 123.txt, there is no save dialog appears.
当我输入不存在的文件名时,这是输出.
When I input filename which does not exist, here is the output.
我希望这会对您有所帮助.
I hope this would be helpful to you.
如果还有其他问题,请随时与我们联系.
If you have something else, please feel free to contact us.
最好的问候,
温迪
这篇关于编码:C#中的SaveAs和Save Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!