For example, how could you programatically "click" on a button in a Form ?
Simple question - What is the equivalent of a "Send Key" ?
Collapse
This topic is closed.
X
X
-
RobTags: None -
=?ISO-8859-1?Q?Lorenz_H=F6lscher?=
Re: Simple question - What is the equivalent of a "Send Key" ?
Hi Rob,
if you have some code like
Private Sub btnOK_Click(... ..)
MsgBox("Hi there")
End Sub
und you want to run it anywhere else simply call this procedure like
any other procedure by its name:
btnOK_Click
If you sometimes don't want to fill in all the arguments of these
reserved event procedures change the code into:
Private Sub btnOK_Click(... ..)
MyOK
End Sub
Private Sub MyOK()
MsgBox("Hi there")
End Sub
and call MyOK instead of btnOK_Click.
bye, Lorenz
-
kimiraikkonen
Re: Simple question - What is the equivalent of a "Send Key" ?
On Sep 29, 1:00 pm, "Rob" <ro...@yahoo.co mwrote:Assuming you have a event sub that handles Button1.Click like:For example, how could you programatically "click" on a button in a Form ?
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
' Code block here when button is pressed
End Sub
....and if you want to execute the same code block inside Button1_Click
as if Button1 is clicked, to do so, you can simply try to call sub
from anywhere:
Button1_Click(s ender, e)
Hope this helps,
Onur Güzel
Comment
-
Bill McCarthy
Re: Simple question - What is the equivalent of a "Send Key" ?
Hi Rob,
"Rob" <robc1@yahoo.co mwrote in message
news:68qdnQnSSP i1NX3VnZ2dnUVZ_ u2dnZ2d@comcast .com...Button has a PerformClick method.For example, how could you programatically "click" on a button in a Form ?
Alternatively use My.Computer.Key board.SendKeys
Comment
-
=?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=
RE: Simple question - What is the equivalent of a "Send Key" ?
I've normally used SendKey to send to an external application. With that in
mind, assuming you want to click a button in an external application, the
equivalent could be to use send keys to send "{ENTER}". You have to navigate
in the external app so the active button is selected. I did this with
sendkeys {TAB}. Fortunatly for me the external application was a well
defined interface, meaning, upon startup, I knew how many tabs to hit to get
to my button of interest.
If you are talking about programatically clicking a button in your own app,
the other answers are appropriate.
"Rob" wrote:
For example, how could you programatically "click" on a button in a Form ?
>
>
>Comment
-
Herfried K. Wagner [MVP]
Re: Simple question - What is the equivalent of a "Send Key" ?
"Rob" <robc1@yahoo.co mschrieb:If you are talking about other processes: P/invoke + 'SendInput'.For example, how could you programatically "click" on a button in a Form ?
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Comment
-
Cor Ligthert[MVP]
Re: Simple question - What is the equivalent of a "Send Key" ?
Rob,
Why would you use an event when you can direct invoke the method?
\\\
Button_ClickEve nt(me,nothing)
///
This works as well as the button has not the focus.
Cor
"Rob" <robc1@yahoo.co mschreef in bericht
news:68qdnQnSSP i1NX3VnZ2dnUVZ_ u2dnZ2d@comcast .com...For example, how could you programatically "click" on a button in a Form ?
>Comment
-
Phill W.
Re: Simple question - What is the equivalent of a "Send Key" ?
Cor Ligthert[MVP] wrote:
Why would you use an event when you can direct invoke the method?Button_ClickEve nt(me,nothing)It might do, but IMHO, it's a bad habit to get into.This works as well as the button has not the focus.
PerformClick() does all the same checks as clicking the button manually
(e.g. you can't PerformClick a disabled button) and you don't have to
worry about getting hold of valid EventArgs to pass to the "method"
call. OK, for Click events they're pretty simple, but just try it with
some of the /other/ events. ;-)
Also, the "sender" argument should be the Control /raising/ the event,
not the form /handling/ it, so ...
Button1_Click( Button1, EventArgs.Empty )
.... would be more correct.
HTH,
Phill W.
Comment
-
Cor Ligthert[MVP]
Re: Simple question - What is the equivalent of a "Send Key" ?
Phill,
Do what you want, I have the oposite expirience as you.
Cor
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschreef in bericht
news:gbt7co$j0t $1@south.jnrs.j a.net...Cor Ligthert[MVP] wrote:
>>>Why would you use an event when you can direct invoke the method?>> Button_ClickEve nt(me,nothing)>>This works as well as the button has not the focus.
It might do, but IMHO, it's a bad habit to get into.
>
PerformClick() does all the same checks as clicking the button manually
(e.g. you can't PerformClick a disabled button) and you don't have to
worry about getting hold of valid EventArgs to pass to the "method" call.
OK, for Click events they're pretty simple, but just try it with some of
the /other/ events. ;-)
>
Also, the "sender" argument should be the Control /raising/ the event, not
the form /handling/ it, so ...
>
Button1_Click( Button1, EventArgs.Empty )
>
... would be more correct.
>
HTH,
Phill W.Comment
-
Tom Shelton
Re: Simple question - What is the equivalent of a "Send Key" ?
On 2008-09-29, Rob <robc1@yahoo.co mwrote:Can you be more specific? Are you talking about a form in your application orFor example, how could you programatically "click" on a button in a Form ?
>
>
in another applciation? In otherwords, cross process or same process?
--
Tom Shelton
Comment
-
Herfried K. Wagner [MVP]
Re: Simple question - What is the equivalent of a "Send Key" ?
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschrieb:I agree. It fulfills the contract of the event. Nevertheless, I would not>>Why would you use an event when you can direct invoke the method?>> Button_ClickEve nt(me,nothing)>>This works as well as the button has not the focus.
It might do, but IMHO, it's a bad habit to get into.
>
PerformClick() does all the same checks as clicking the button manually
(e.g. you can't PerformClick a disabled button) and you don't have to
worry about getting hold of valid EventArgs to pass to the "method" call.
OK, for Click events they're pretty simple, but just try it with some of
the /other/ events. ;-)
>
Also, the "sender" argument should be the Control /raising/ the event, not
the form /handling/ it, so ...
>
Button1_Click( Button1, EventArgs.Empty )
>
... would be more correct.
call the event handler directly.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Comment
Comment