我有这样的代码:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
string ext = Path.GetExtension(openFileDialog1.FileName);
if(string.Compare(ext, ".FDB") == 0)
{
string fileName = openFileDialog1.SafeFileName;
string fileDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
string databaseTxt = @"C:\Users\arist\AppData\Roaming\TDWork\";
string[] database = { fileDirectory + fileName };
if (Directory.Exists(databaseTxt))
{
System.IO.File.WriteAllLines(databaseTxt + "databases.txt", database);
}
else
{
DirectoryInfo di = Directory.CreateDirectory(databaseTxt);
System.IO.File.WriteAllLines(databaseTxt + "databases.txt", database);
}
}
else
{
MessageBox.Show("Fajl koji ste izabrali nije Firebird baza (.FDB)");
e.Cancel = true;
}
}
现在,我想创建更多打开相同文件对话框的按钮。问题是我想将 openFileDialog 目录传递给不同的文本框。所以逻辑是这样的:
如果我用button1打开,将值传递给textbox1,如果我用button2打开,将值传递给textbox2,如果我用button3打开,将值传递给textbox3。
所以我想创建 int check (1, 2, 3) 所以当我按下 button1 时,它将 check = 1 传递给 OpenDialog1_FileOk,所以我只是切换到那里并执行操作。
问题是我不知道如何将它传递给处理程序,如果可能的话。另外,如果有其他解决方案,请写出来。