469,366 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Force button event?

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
Nov 21 '05 #1
14 7328
Adam Honek wrote:
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"

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #2
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

"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Adam Honek wrote:
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"

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.

Nov 21 '05 #3
Adam,

myButton.PerformClick might be what you need.

Kerry Moorman
"Adam Honek" wrote:
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

Nov 21 '05 #4
Adam Honek wrote:
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.

--

(O)enone
Nov 21 '05 #5
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
Nov 21 '05 #6
Bingo, exactly what I need.

Geez they've sure changed things round.

Thanks,
Adam

"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
Adam,

myButton.PerformClick might be what you need.

Kerry Moorman
"Adam Honek" wrote:
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

Nov 21 '05 #7
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8
Adam,

This one does it forever.

button_Click(nohing,nothing)

I hope this helps,

Cor
Nov 21 '05 #9
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
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).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10
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
Nov 21 '05 #11
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
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.


'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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12
Herfried,
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.

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

Nov 21 '05 #13
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
Nov 21 '05 #14
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
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)'!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Marco Maroni | last post: by
1 post views Thread by JezB | last post: by
8 posts views Thread by Amirallia | last post: by
8 posts views Thread by Keith H | last post: by
4 posts views Thread by Jordi Rico | last post: by
1 post views Thread by BudhramM | last post: by
4 posts views Thread by anudu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.