calling a method associated to an event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abdessamad Belangour

    calling a method associated to an event

    Hi all,
    Suppose we have a method associated to a button object. Clicking on this
    button triggers the associated method. for example : private void
    btnAdd_Click(ob ject sender, System.EventArg s e)
    How can i do if i want to call it without the button been clicked ?
    Thanks.


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: calling a method associated to an event

    Abdessamad,

    The method that you attach is just that, a method, so you can call it
    normally, passing the parameters that you want to pass. You can pass null,
    like this:

    // Call the event handler.
    btnAdd_Click(nu ll, null);

    But you have to be careful, because the button handler code might be
    depending on those parameters. Most likely, you will want to simulate a
    button click like this:

    // Call the event handler.
    btnAdd_Click(bt nAdd, EventArgs.Empty );

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Abdessamad Belangour" <belangour@irin .univ-nantes.fr> wrote in message
    news:ObWXLomvDH A.3532@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi all,
    > Suppose we have a method associated to a button object. Clicking on this
    > button triggers the associated method. for example : private void
    > btnAdd_Click(ob ject sender, System.EventArg s e)
    > How can i do if i want to call it without the button been clicked ?
    > Thanks.
    >
    >[/color]


    Comment

    Working...