Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个屏幕,上面有五十多个按钮。我希望能够检测到单击了哪个按钮,然后根据单击的按钮进入另一个带有数据的屏幕。但是,如果不使用特定的按钮名称,我似乎无法检测到鼠标的点击。如果可能,我想避免使用 50+ OnEvent() 函数。如果没有,我就把它们都写出来。
任何关于我如何去做的建议都将不胜感激,谢谢!
你正在使用 C#?C++?VB.NET?爪哇?C#代码:
这是一个事件作为示例:
private void button1_Click(object sender, EventArgs e) { if (sender is Button) { MessageBox.Show((sender as Button).Name); } }
您可以替换 MessageBox,它只是为了举例说明。