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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -