[英]Can't click programmatically added buttons
我是以编程方式向表单添加按钮,由于某种原因我无法单击它。 为什么不?
private Button btnBrowser = new Button();
this.btnBrowser.Text = "Open Browser";
this.btnBrowser.Location = new System.Drawing.Point(55, 45);
this.btnBrowser.Size = new System.Drawing.Size(70, 30);
这会将按钮添加到表单中,但我无法单击它。
private void btnBrowser_Click(object sender, EventArgs e)
{
MessageBox.Show("test");
}
确保将其添加到表单中,然后添加事件处理程序:
this.Controls.Add(btnBrowser);
btnBrowser.Click += btnBrowser_Click;
var btnBrowser = new Button();
btnBrowser.Text = "Open Browser";
btnBrowser.Location = new System.Drawing.Point(55, 45);
btnBrowser.Size = new System.Drawing.Size(70, 30);
btnBrowser.Click += (o, evt) =>
{
MessageBox.Show("test");
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.