WPF C# button click event in code behind -


i have create button in code behind , how write click event? mousedown? ? want detect if button being pressed populate textbox text.

button btn1 = new button(); btn1.content = qhm.option1; sp1.children.add(btn1);  if (btn1.mousedown = true) {    tbox.text = qhm.option1; } 

like that:

button btn1 = new button(); btn1.content = qhm.option1; btn1.click += btn_click; sp1.children.add(btn1);   //separate method private void btn_click(object sender, routedeventargs e) {     tbox.text = qhm.option1; } 

using lambda:

btn1.click += (source, e) => {         tbox.text = qhm.option1; }; 

you can access local variables.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -