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. Events Between Two Controls

Events Between Two Controls

Scheduled Pinned Locked Moved C#
help
11 Posts 4 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.
  • J Offline
    J Offline
    joshp1217
    wrote on last edited by
    #1

    Ok I have two controls, Ok Control X and Control Y, I want control X to be able to raise in event that Control Y is listening for when Control Y hears this event it responds by raising an event/events Control X is listening for and in Turn Control X does some work or method call etc. Any help would be greatly appreciated. Thank you

    J M J 3 Replies Last reply
    0
    • J joshp1217

      Ok I have two controls, Ok Control X and Control Y, I want control X to be able to raise in event that Control Y is listening for when Control Y hears this event it responds by raising an event/events Control X is listening for and in Turn Control X does some work or method call etc. Any help would be greatly appreciated. Thank you

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      X->Y->X->Y... Sounds like infinite looping here :confused: Best, Jun

      J 1 Reply Last reply
      0
      • J joshp1217

        Ok I have two controls, Ok Control X and Control Y, I want control X to be able to raise in event that Control Y is listening for when Control Y hears this event it responds by raising an event/events Control X is listening for and in Turn Control X does some work or method call etc. Any help would be greatly appreciated. Thank you

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        I hope I got it right! // UserControlX public class X : UserControl { private X _instance; private Y _y; //Constructor public X() { _y = Y.GetInstance(); _y.YChanged+= new event(_yChanged); } public event EventHandler XChanged; private void _yChanged(object sender, event e) { //#3 MethodEnd(); } public static X GetInstance() { if(_instance==null) { _instance = new X(); } return _instance; } private void MethodStart() { //#1 //Here it starts if(XChanged!=null) { XChanged(this, EventArgs.Empty); } } private void MethodEnd() { //#4 //Good luck!! Martin } } // UserControlY public class Y : UserControl { private Y _instance; private X _x; //Constructor public Y(); { _x = X.GetInstance(); _x.XChanged+= new event(_xChanged); } public event EventHandler YChanged; private void _xChanged(object sender, event e) { //#2 if(YChanged!=null) { YChanged(this, EventArgs.Empty); } } public static Y GetInstance() { if(_instance==null) { _instance = new Y(); } return _instance; } }

        1 Reply Last reply
        0
        • J Jun Du

          X->Y->X->Y... Sounds like infinite looping here :confused: Best, Jun

          J Offline
          J Offline
          joshp1217
          wrote on last edited by
          #4

          Yeah I am kinda confused myself but it shouldnt end up falling into an infinite loop. Ok here is a long explanation that hopefully will make it more clear. I have a side bar with buttons on it, each button corresponding to a specific form that will be loaded in to a panel on the same form as the SideBar/ToolBar. Ok hope ur still with me...lol..Alright now these forms are independent of the Toolbar but the tools bars controls the user navigation from form to form. If a user clicks on one of the buttons(wanting to change to another form) I want to currently active form(the form that is being viewed) to know that an attempt to unload it and load another form is about to happen, if this form is at a critical point in its process it needs to be able to say NO dont change me yet and stop the process of the visual unloading of the form and prompting the user to finish whatever he needs to finish and they attempt a change later. SOOO with all of that, that is why I have a Control X(toolbar) that wants to raise an event to control Y(Form in Panel), Control Y(Form in Panel) will listen for this event, if it is at a point of being able to allow a change then it sends a response back to the Control X(Toolbar) allowing the change of forms to happen. I hope this explains it more clearly. I understand what i need to do, i am just trying to find some code examples to begin to lead me down the right path to see if i am right or not. Thanks for all the help.

          M 2 Replies Last reply
          0
          • J joshp1217

            Yeah I am kinda confused myself but it shouldnt end up falling into an infinite loop. Ok here is a long explanation that hopefully will make it more clear. I have a side bar with buttons on it, each button corresponding to a specific form that will be loaded in to a panel on the same form as the SideBar/ToolBar. Ok hope ur still with me...lol..Alright now these forms are independent of the Toolbar but the tools bars controls the user navigation from form to form. If a user clicks on one of the buttons(wanting to change to another form) I want to currently active form(the form that is being viewed) to know that an attempt to unload it and load another form is about to happen, if this form is at a critical point in its process it needs to be able to say NO dont change me yet and stop the process of the visual unloading of the form and prompting the user to finish whatever he needs to finish and they attempt a change later. SOOO with all of that, that is why I have a Control X(toolbar) that wants to raise an event to control Y(Form in Panel), Control Y(Form in Panel) will listen for this event, if it is at a point of being able to allow a change then it sends a response back to the Control X(Toolbar) allowing the change of forms to happen. I hope this explains it more clearly. I understand what i need to do, i am just trying to find some code examples to begin to lead me down the right path to see if i am right or not. Thanks for all the help.

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Is the toolbar on a main form, which has also the instances of the forms? Are you whant to hide the forms or dispose them, when changing to an other?

            J 1 Reply Last reply
            0
            • J joshp1217

              Yeah I am kinda confused myself but it shouldnt end up falling into an infinite loop. Ok here is a long explanation that hopefully will make it more clear. I have a side bar with buttons on it, each button corresponding to a specific form that will be loaded in to a panel on the same form as the SideBar/ToolBar. Ok hope ur still with me...lol..Alright now these forms are independent of the Toolbar but the tools bars controls the user navigation from form to form. If a user clicks on one of the buttons(wanting to change to another form) I want to currently active form(the form that is being viewed) to know that an attempt to unload it and load another form is about to happen, if this form is at a critical point in its process it needs to be able to say NO dont change me yet and stop the process of the visual unloading of the form and prompting the user to finish whatever he needs to finish and they attempt a change later. SOOO with all of that, that is why I have a Control X(toolbar) that wants to raise an event to control Y(Form in Panel), Control Y(Form in Panel) will listen for this event, if it is at a point of being able to allow a change then it sends a response back to the Control X(Toolbar) allowing the change of forms to happen. I hope this explains it more clearly. I understand what i need to do, i am just trying to find some code examples to begin to lead me down the right path to see if i am right or not. Thanks for all the help.

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Does the active form just say no change now, or should the form finish automaticaly later?

              J 1 Reply Last reply
              0
              • M Martin 0

                Is the toolbar on a main form, which has also the instances of the forms? Are you whant to hide the forms or dispose them, when changing to an other?

                J Offline
                J Offline
                joshp1217
                wrote on last edited by
                #7

                The unload of the forms is just a visual unload, the user can go back to a form and the same data should be showing on the form once it left. And yes the Toolbar is a control it self and is loaded onto the main form. The Toolbar/sidebar looks similar to Outlook 2003's sidebar, the sliding effect with the buttons and what not, if a button is click then the form in the viewing panel changes, but it should only change if the actively viewable form allows the change to happen, but that is at that specific forms discretion.

                1 Reply Last reply
                0
                • M Martin 0

                  Does the active form just say no change now, or should the form finish automaticaly later?

                  J Offline
                  J Offline
                  joshp1217
                  wrote on last edited by
                  #8

                  The form will tell the toolbar, "I can't change now" etc. and the Tool bar will inturn get this response and give a response of its on to the User and stop the process of changing the actively viewable form. Tough problem huh, yeah i am having a tough time wrapping my brain around it too, but hey it is fun. Thanks for all the help i really appreciate this.

                  M 2 Replies Last reply
                  0
                  • J joshp1217

                    The form will tell the toolbar, "I can't change now" etc. and the Tool bar will inturn get this response and give a response of its on to the User and stop the process of changing the actively viewable form. Tough problem huh, yeah i am having a tough time wrapping my brain around it too, but hey it is fun. Thanks for all the help i really appreciate this.

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #9

                    No fear, we will find a solution!

                    1 Reply Last reply
                    0
                    • J joshp1217

                      The form will tell the toolbar, "I can't change now" etc. and the Tool bar will inturn get this response and give a response of its on to the User and stop the process of changing the actively viewable form. Tough problem huh, yeah i am having a tough time wrapping my brain around it too, but hey it is fun. Thanks for all the help i really appreciate this.

                      M Offline
                      M Offline
                      Martin 0
                      wrote on last edited by
                      #10

                      I realy think its not so difficult. 1) the main form gets all the instances. 2) you start with an default form1 in the panel. 3) all your form classes (Better to make a YourBaseForm) need an public Method public virtual bool ReadyToChange() //You can override it in your specific form classes { if(//everything is ok == true) {return true;} else {return false;} } 4) the main form has an additional YourBaseForm instance, which is called actform. 5) at startup actform = form1 6) at the Click Events you just have to check: if(actform.ReadyToChange) { formx.Show(); actform.Hide(); actform = formx; } else { //Message: Its not possible to change form. } Hope I got it now All the best and good luck, Martin -- modified at 16:55 Thursday 29th June, 2006

                      1 Reply Last reply
                      0
                      • J joshp1217

                        Ok I have two controls, Ok Control X and Control Y, I want control X to be able to raise in event that Control Y is listening for when Control Y hears this event it responds by raising an event/events Control X is listening for and in Turn Control X does some work or method call etc. Any help would be greatly appreciated. Thank you

                        J Offline
                        J Offline
                        Josh Smith
                        wrote on last edited by
                        #11

                        I would inject an event broker between the two controls. The broker would take care of notifying each control of when it should do it's work, based on the events fired by the other control. This technique will localize the event coordination logic, so that it's not spread out between multiple classes/methods. Josh

                        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