如果我有一个绘制矩形,圆形和线条的程序,我想使用SaveFileDialog保存用户在表单上绘制的图片,这将如何完成?
我知道如何使用SaveFileDialog保存文本文件,只是不知道如何保存表单.
我想使用SaveFileDialog控件保存文件。为什么文件必须已经存在才能保存?
这是我正在使用的代码:
string month = dateTimePicker1.Value.Month.ToString();
string year = dateTimePicker1.Value.Year.ToString();
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = @"C:\";
saveFileDialog1.Title = "Save Sql Files";
saveFileDialog1.FileName = "MysqlBackup-"+month+"-"+year+".sql";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.DefaultExt = "Sql";
saveFileDialog1.Filter = "Sql files (*.Sql)|*.Sql";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Here is the error. After typing in the filename, when I click OK it gives me an error stating that the file does not exist.
}
Run Code Online (Sandbox Code Playgroud) 我想从"保存"对话框中提取所选路径,不包括文件名.
以下代码检索完整路径+文件名及其扩展名.
placeToSaveDocument = Path.GetFullPath(saveFileDialog.FileName);
Run Code Online (Sandbox Code Playgroud)
请不要建议使用文件夹浏览器对话框,因为我有理由不使用它.
有任何想法吗?
我的程序中有一个SaveFileDialog.问题是当我在对话框上单击"取消"时,另一个SaveFileDialog打开.但是,当我点击取消第二SaveFileDialog,第三确实不出现,所以它不是一个圈或类似的东西.我无法看到是什么导致我的SaveFileDialog以如此奇怪的方式表现.显然我需要修复它,以便如果用户在第一个SaveFileDialog上单击取消,它会将它们返回到表单.
保存在我的程序中的代码如下:
private void SaveFile()
{
if (filepath == null)
{
SaveFileAs();
}
else
{
StreamWriter sw = new StreamWriter(filepath);
try
{
sw.WriteLine(richTextBoxPrintCtrl1.Rtf);
richTextBoxPrintCtrl1.Modified = false;
sw.Close();
lastsave.Text = "Last Saved: " + DateTime.Now.ToString();
}
catch (Exception exc)
{
MessageBox.Show("Failed to save file. \n \n" + exc.Message);
}
finally
{
if (sw != null) sw.Close();
}
Run Code Online (Sandbox Code Playgroud)
和SaveFileAs
private void SaveFileAs()
{
SaveFileDialog sfdSaveFile = new SaveFileDialog();//Creates a new instance of the SaveFileDialog
sfdSaveFile.Title = "Save File";//The title of …Run Code Online (Sandbox Code Playgroud)