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 - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -