Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Calling a button event from another page in c#

Calling a button event from another page in c#

Scheduled Pinned Locked Moved C#
csharphelpwinformslearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Malayil alex
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • M Malayil alex

      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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • C Colin Angus Mackay

        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

        J Offline
        J Offline
        javiersolis1983
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups