I have code which generates buttons dynamically
Button txt = new Button();
this.Controls.Add(txt);
txt.Top = cleft * 40;
txt.Name = "txt_" + cb;
txt.Size = new Size(200, 16);
txt.Left = 150;
But I cannot think how to generate its click event.
I assume you don't mean "how to generate", but rather how to handle. Since you have a reference to your dynamic button, just add an event handler:
txt.Click += new EventHandler(eventHandlerFunction);
Or use a lambda:
txt.Click += (object sender, EventArgs e) => ...;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments