简体   繁体   English

使用C#将其另存为Windows Form App中

[英]save and save as in Windows Form App by C#

I'm using this code for making save as of image in c# 我正在使用此代码在c#中将图像另存为

SaveFileDialog svf = new SaveFileDialog();
        svf.Filter = "JPEG files (*.jpeg)|*.jpeg";
        if (DialogResult.OK == svf.ShowDialog())
        {
            this.imgbox.Image.Save(svf.FileName,ImageFormat.Jpeg);
        }

I need to make save now for image without change name or location ( apply save not save as as the above code ) how i can use this code for save now ? 我需要立即保存图像而不更改名称或位置(应用保存而不保存为上述代码),如何使用此代码立即保存?

Assuming WinForms, add a field or property to the appropriate control to hold the full path to the file currently opened, and call it currentFileName or something. 假设使用WinForms,请将字段或属性添加到适当的控件中,以保存当前打开的文件的完整路径,并将其命名为currentFileName或其他名称。

When opening a file, assign the path to the variable. 打开文件时,将路径分配给变量。 Now when the user hits the Save menu, you can use the already stored path to overwrite the opened file. 现在,当用户单击“保存”菜单时,您可以使用已存储的路径来覆盖打开的文件。 You can add a Save As menu that pops up the SaveFileDialog , and afterwards assigns the result to the variable again - if not cancelled. 您可以添加一个另存为菜单,该菜单会弹出SaveFileDialog ,然后将结果再次分配给变量-如果未取消的话。

When the user invokes the New or Close menu, make sure to clear the stored path. 当用户调用“新建”或“关闭”菜单时,请确保清除存储的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM