Calling a button event from another page in c#
-
Hello , I am a beginner in c#.net, currently i am working on c#.net windows forms. My problem is i want to call a button event of let's say form1 from form2. what i did is make an object of form1 and call that button event, but it's not working. I need your help immediately pls give me ur idea, alex. Help me
-
Hello , I am a beginner in c#.net, currently i am working on c#.net windows forms. My problem is i want to call a button event of let's say form1 from form2. what i did is make an object of form1 and call that button event, but it's not working. I need your help immediately pls give me ur idea, alex. Help me
SOunds like your application architecture isn't right. You shouldn't be doing this. The button event on form one should be activated only from the button itself. Nothing else should call it. Some ideas: Refactor the code for the event into a separate method and call that method from the other form. Refactor the code for the events into a controller class and have the event handlers call into the controller. The code in the form2 would also call into the controller instead of directly to the form1.
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
-
SOunds like your application architecture isn't right. You shouldn't be doing this. The button event on form one should be activated only from the button itself. Nothing else should call it. Some ideas: Refactor the code for the event into a separate method and call that method from the other form. Refactor the code for the events into a controller class and have the event handlers call into the controller. The code in the form2 would also call into the controller instead of directly to the form1.
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
yes. i think the same as colin. But if you want to do this you might declare the event of this button as public instead of private. But what you are trying to do isnt right.