简体   繁体   English

在SaveFileDialog中更改文件名

[英]change name of file in SaveFileDialog

in my WinFormsApp user can add picture in a folder of hardDrive with SaveFileDialog. 在我的WinFormsApp用户中,可以使用SaveFileDialog将图片添加到hardDrive的文件夹中。 if there is a picture the same name as new picture an alert is shown that user must rename the new picture. 如果存在与新图片同名的图片,则会显示警告,提示用户必须重命名新图片。

how can I change name of the picture with adding a variable integer to name without changing name with user? 如何在不使用用户更改名称的情况下向名称添加变量整数来更改图片名称?

The SaveFileDialog class has a public FileName property that allows you to get or set the file name displayed in the dialog box. SaveFileDialog类具有公共的FileName属性 ,该属性使您可以获取或设置对话框中显示的文件名。

This is how you retrieve the file name that the user specified after they have dismissed the dialog box, but it is also the way that you specify a default file name that initially appears in the dialog box. 这是检索用户关闭对话框后指定的文件名的方法,但这也是指定最初出现在对话框中的默认文件名的方式。

So before you call the SaveFileDialog.ShowDialog method, just set the FileName property to the desired file name. 因此,在调用SaveFileDialog.ShowDialog方法之前,只需将FileName属性设置为所需的文件名。 If you like, you can retrieve its current value, append a number to it, and set the property to the new string. 如果愿意,可以检索其当前值,在其后面附加一个数字,然后将该属性设置为新字符串。

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

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