Not being able to add button click event in c# -



Not being able to add button click event in c# -

i have code generates me buttons foreach loop.

controls.button btn = new controls.button(); btn.button1.text = "details"; btn.location = new point(200, cnt); panel1.controls.add(btn);

when seek after doesn't work.

private void button1_click(object sender,eventargs e) { messagebox.show(""); }

any idea?

controls.button btn = new controls.button(); btn.id= "id" + counter; btn.button1.text = "details"; btn.location = new point(200, cnt); btn.click += button1_click; panel1.controls.add(btn);

you should write ! aware in case of button in foreach method have same click event handler. have id + counter of buttons create differnce them.

private void button1_click(object sender,eventargs e) { string id= ((button)sender).id; if(id == "value") { } else if(id == "another value") { messagebox.show(""); } }

c#

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -