【发布时间】:2015-12-11 07:29:30
【问题描述】:
这是我的 C# 代码。
但是每次我运行这段代码时,每当我单击左键时,文件都会保存在默认路径中:“C:\NewFolder\”
但我不知道如何将使用右键单击选择的文件夹永久设置为我的默认文件夹。
在我使用右键单击选择一个文件夹后,每当我运行 exe 文件时,该文件应保存在该选定文件夹中
string folderpath = "C:\\NewFolder\\";
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
bool exists = System.IO.Directory.Exists(folderpath);
if (!exists)
System.IO.Directory.CreateDirectory(folderpath);
this.Hide();
System.Threading.Thread.Sleep(1000);
SendKeys.Send("{PRTSC}");
Image img = Clipboard.GetImage();
img.Save(folderpath + "\\" + DateTime.Now.Ticks + ".jpg");
this.Show();
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
folderpath = folderBrowserDialog1.SelectedPath;
}
}
}
【问题讨论】: