我正在修改https://github.com/alexjwong/file-encrypt-decrypt,以便它不需要openFileDialog,而是可以直接设置文件路径。我试过强制私有String FilePath ="&#34 ;;私有字符串FilePath =" C:\ Path \ To \ my \ File.txt.des&#34 ;;
当我尝试这个时,我收到了错误。不支持给定路径的格式。然后我尝试使用@" C:\ Path \ To \ my \ File.txt.des"但得到了同样的错误。我决定尝试使用openFileDialog。它毫无障碍地工作。
// Set filter options and filter index.
openFileDialog.Filter = "All Files (*.*)|*.*|Encrypted Files (*.des)|*.des";
openFileDialog.FilterIndex = 1;
// Use openFileDialog tool (in designer) to create openFileDialog1
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
FilePath = openFileDialog.FileName;
this.Invalidate();
这是打开文件对话框的代码。我怎么能强制Form加载文件路径?
答案 0 :(得分:-1)
将我的代码更改为
FilePath = "C:\\Users\\prefo\\Desktop\\test.txt.des";
this.Invalidate();
它有效!