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
Post a Comment