c# - Handling Button Clicks from a different Class -



c# - Handling Button Clicks from a different Class -

i have form button buttongo.

and have class takes button through constructor, handles events:

public class handlingclass {//....... button go ; public handlingclass(button btn) { this.go = btn; this.go.click += new eventhandler(this.go_click); } //..... public void go_click(object sender, eventargs e) { //logic here }

what doing wrong, , why isn't event beingness raised when press button in caller form?

this code works me

public class handlingclass { button go; public handlingclass(button btn) { go = btn; go.click += go_click; } void go_click(object sender, routedeventargs e) { throw new notimplementedexception(); } }

and in loaded event of class having button add together below code

void mainwindow_loaded(object sender, routedeventargs e) { handlingclass hc=new handlingclass(**mybutton**); }

mybutton should reference button.

c# class event-handling

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -