Force button event?

  • Thread starter Thread starter Adam Honek
  • Start date Start date
A

Adam Honek

Hello,

I have a form with several buttons.

If a user clicks on one I want it to call the Click() event of another
button.

In VB6 this is very easy but they've changed it in .NET.

Can't we just do: call mybutton_click() anymore?

Thanks,
Adam Honek
 
Adam said:
Hello,

I have a form with several buttons.

If a user clicks on one I want it to call the Click() event of another
button.

In VB6 this is very easy but they've changed it in .NET.

Can't we just do: call mybutton_click() anymore?

Thanks,
Adam Honek

have you tried using "Handles Button2.Click"
 
Yes but it won't work.

Right now I have something like this:

If e.KeyCode = Keys.Enter Then

handles btnX.Click()

End If

Adam
 
Adam said:
Can't we just do: call mybutton_click() anymore?

You can (though you'll have to pass the appropriate parameters), but a
better way is to call the button's PerformClick method.
 
Bingo, exactly what I need.

Geez they've sure changed things round.

Thanks,
Adam
 
The way I would do this is write a freestanding subroutine to do what I
wanted, then call it from both button click subroutines at the appropriate
time.

Bobbo
 
Adam Honek said:
I have a form with several buttons.

If a user clicks on one I want it to call the Click() event of another
button.

In VB6 this is very easy but they've changed it in .NET.

Can't we just do: call mybutton_click() anymore?

If the button is visible and enabled, you can call its 'PerformClick'
method. Alterantively you can take the code from the event handler and put
it into a separate procedure. This procedure can be called from within the
event handler and other procedures. If you really want to call the button's
'Click' event handler for some reason, you can pass 'EventArgs.Empty' in the
'e' parameter.
 
Adam,

This one does it forever.

button_Click(nohing,nothing)

I hope this helps,

Cor
 
Cor,

Cor Ligthert said:
This one does it forever.

button_Click(nohing,nothing)

Mhm... I would not use this one, because the event contract will be broken
(no sender and event arguments are sent).
 
Herfried,
Mhm... I would not use this one, because the event contract will be
broken (no sender and event arguments are sent).

Ignoring the nohing (typo). I thought today, let me do it very clean. I
used the performclick. Because of your message in this thread, do I now know
why that did not go.

Maybe you understand now as well why I made this message, it was to help the
OP not to have the same problem as me today.

:-)

By the way when what you tell is a problem than a simple
\\\
If sender is Nothing then 'do something
or in VB2005
If Not sender IsNot Nothing then 'do something
///

Does overcome that problem

:-)

Cor
 
Cor,

Cor Ligthert said:
Ignoring the nohing (typo). I thought today, let me do it very clean. I
used the performclick. Because of your message in this thread, do I now
know why that did not go.

'PerformClick' actually works under certain circumstances.
Maybe you understand now as well why I made this message, it was to help
the OP not to have the same problem as me today.

Sorry, I cannot follow you...
By the way when what you tell is a problem than a simple
\\\
If sender is Nothing then 'do something
or in VB2005
If Not sender IsNot Nothing then 'do something
///

I prefer 'If Not sender Is Nothing Then...' or 'If sender IsNot Nothing
Then...' ;-). However, I'd try to avoid this situation.
 
Herfried,
I had this problem today because as what you had described in this thread.

I tried to help the OP by giving the (nothing nothing) code, so that (let us
say), have the same problems, knows how to fix that.

By the way. The performclick is AFAIK only creating a
callEventFunction(nothing, nothing).

Cor
 
sht
so that (let us say), have the same problems, knows how to fix that.

so that (let us say) when he has the same problems, knows how to fix that

Cor
 
Cor,

Cor Ligthert said:
By the way. The performclick is AFAIK only creating a
callEventFunction(nothing, nothing).

No, it isn't. It's creating a '(<reference to sender>, EventArgs.Empty)'!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top