button click

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hrvoje Voda

    button click

    How can I have more the one event on button click?

    First click --> one event
    Second click --> second event

    Hrcko


  • Tim Haughton

    #2
    Re: button click

    "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
    news:df1229$nna $1@ss405.t-com.hr...[color=blue]
    > How can I have more the one event on button click?
    >
    > First click --> one event
    > Second click --> second event[/color]

    You could make do with 1 event if you have the client's handler remove
    itself and add another handler...

    private void OnClick( object sender, ClickEventArgs e )
    {
    // Do something
    myForm.Click -= new ClickEventHandl er( OnClick );
    myForm.Click += new ClickEventHandl er( OnSecondClick );
    }

    private void OnSecondClick( object sender, ClickEventArgs e )
    {
    // Do something
    myForm.Click -= new ClickEventHandl er( OnSecondClick );
    myForm.Click += new ClickEventHandl er( OnClick );
    }


    Or, you could simply create a custom control with 2 events.

    --
    Regards,

    Tim Haughton

    Agitek




    Comment

    • Rick Lones

      #3
      Re: button click

      Hrvoje Voda wrote:[color=blue]
      > How can I have more the one event on button click?
      >
      > First click --> one event
      > Second click --> second event
      >[/color]

      Depends on your requirements. It sounds like some kind of state machine you are
      after here. The state could be held in a class variable or even in the control
      itself - the Tag property comes to mind. Or if a simple toggle is all you need
      you can even do something really ugly like:

      if (btn.Caption == "On")
      {
      turn_the_damn_t hing_on();
      btn.Caption = "Off";
      }
      else
      {
      turn_the_damn_t hing_off();
      btn.Caption = "On";
      }

      Crude but effective,
      -rick-

      Comment

      • Rick Lones

        #4
        Re: button click

        Hrvoje Voda wrote:[color=blue]
        > How can I have more the one event on button click?
        >
        > First click --> one event
        > Second click --> second event
        >[/color]

        Depends on your requirements. It sounds like some kind of state machine you are
        after here. The state could be held in a class variable or even in the control
        itself - the Tag property comes to mind. Or if a simple toggle is all you need
        you can even do something really ugly like:

        if (btn.Caption == "On")
        {
        turn_the_damn_t hing_on();
        btn.Caption = "Off";
        }
        else
        {
        turn_the_damn_t hing_off();
        btn.Caption = "On";
        }

        Crude but effective,
        -rick-

        Comment

        Working...