创建按钮点击事件C# [英] Created Button Click Event c#
本文介绍了创建按钮点击事件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用
按钮buttonOk =新按钮()按钮;
随着其他代码,如何检测,如果创建的按钮被点击?
,并使其如果单击窗体将关闭?
解决方案
公开主窗口()
{
//这个按钮必须在窗体上存在。
myButton.Click + = myButton_Click;
}
无效myButton_Click(对象发件人,RoutedEventArgs E)
{
MessageBox.Show(消息在这里);
this.Close();
}
I have made a button using
Button buttonOk = new Button();
along with other code, how can I detect if the created button has been clicked? And make it that if clicked the Form will close?
解决方案
public MainWindow()
{
// This button needs to exist on your form.
myButton.Click += myButton_Click;
}
void myButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Message here");
this.Close();
}
这篇关于创建按钮点击事件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文