在我的C# Windows Forms表单中,我有一些动态生成的按钮。我在点击事件上分配了以下方法。是否可能从触发事件的按钮获取按钮的名称?
private void btnBrowsDoc_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog().Equals(DialogResult.OK))
{
gbxDocument.Controls["txtDocument" + count].Text =
openFileDialog1.FileName;
}
else
{
return;
}
}
catch (Exception ex)
{
//handle the exception
}
}
try...catch
?- 这通常是一种相当糟糕的编程风格,特别是如果您没有评估捕获的异常。 - Uwe Keim