C#: How to remove delegation of a ToolBarButton's click event...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saravanan Krishnan
    New Member
    • Mar 2008
    • 11

    C#: How to remove delegation of a ToolBarButton's click event...

    Hi, everybody...

    I'm developing a c# windows application where my app has more than 2 forms in it. i've placed some toolbarbuttons on it. I've associated toolbarbuttons click events to it. Now what i need is to remove the associated methods of those tbbtns on some condition. I'm able to add delegates to those btns at any moment but i have no idea how to remove those delegations...

    Any help is appriciable...

    Thanks in advance.

    Saravanan Krishnan
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Originally posted by Saravanan Krishnan
    Hi, everybody...

    I'm developing a c# windows application where my app has more than 2 forms in it. i've placed some toolbarbuttons on it. I've associated toolbarbuttons click events to it. Now what i need is to remove the associated methods of those tbbtns on some condition. I'm able to add delegates to those btns at any moment but i have no idea how to remove those delegations...

    Any help is appriciable...

    Thanks in advance.

    Saravanan Krishnan

    Hello Saravanan,

    You can just remove delegate.

    Following is a sample that describes how to remove an event delegate.

    Code:
    //delegate is added for button click event
    this.button2.Click += new System.EventHandler(this.button2_Click);
    
    //delegate for button click event is removed
    this.button2.Click -= new System.EventHandler(this.button2_Click);

    - Balaji U

    Comment

    • Saravanan Krishnan
      New Member
      • Mar 2008
      • 11

      #3
      hey bala,

      i've did same thing to remove the button's association with the event handler method. that is

      btn.click -= new eventhandler(my btn_click);

      but when the other form is opened i execute the above mentioned line. but even then when the same button in the current form(newly opened) is clicked, the event handler method present in the previously opened form gets executed and then the newly opened forms method gets executed.

      I Conform that "[btn.click -= new eventhandler(my btn_click);"] gets executed, but then also mybtn_click() method is called first. How is this possible after removing the delegation for that btn and method...

      if u dont understand this reply u can ask for the code as well...

      Comment

      • balame2004
        New Member
        • Mar 2008
        • 142

        #4
        Originally posted by Saravanan Krishnan
        hey bala,

        i've did same thing to remove the button's association with the event handler method. that is

        btn.click -= new eventhandler(my btn_click);

        but when the other form is opened i execute the above mentioned line. but even then when the same button in the current form(newly opened) is clicked, the event handler method present in the previously opened form gets executed and then the newly opened forms method gets executed.

        I Conform that "[btn.click -= new eventhandler(my btn_click);"] gets executed, but then also mybtn_click() method is called first. How is this possible after removing the delegation for that btn and method...

        if u dont understand this reply u can ask for the code as well...

        Hello,

        Please provide me comple source code so I can able to look into your problem.

        - Balaji

        Comment

        Working...