我有这样的代码:传递值到处理器
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目录传递给不同的文本框。因此,逻辑是这样的:
如果我和按钮1,通价值TextBox1中, 如果我BUTTON2开开,传递价值TextBox2中, 如果我BUTTON3打开,传递价值textbox3。所以我想创建int检查(1,2,3),所以当我按下button1时,它将check = 1传递给OpenDialog1_FileOk,所以我只是在那里切换并执行操作。
问题是我不知道如何将它传递给处理程序,如果这是可能的。如果还有其他解决方案,请写下来。
你想在哪里使用文本框? –
@MongZhu不通,只要显示 – Pacijent
好,那你想在哪里显示呢?在同一个“形式”?或在'OpenfileDialog'中? –