473,487 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simple question - What is the equivalent of a "Send Key" ?

Rob
For example, how could you programatically "click" on a button in a Form ?
Sep 29 '08 #1
10 2251
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
Sep 29 '08 #2
On Sep 29, 1:00*pm, "Rob" <ro...@yahoo.comwrote:
For example, how could you programatically "click" on a button in a Form ?
Assuming you have a event sub that handles Button1.Click like:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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(sender, e)
Hope this helps,

Onur Güzel
Sep 29 '08 #3
Hi Rob,

"Rob" <ro***@yahoo.comwrote in message
news:68******************************@comcast.com. ..
For example, how could you programatically "click" on a button in a Form ?
Button has a PerformClick method.
Alternatively use My.Computer.Keyboard.SendKeys

Sep 29 '08 #4
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 ?
Sep 29 '08 #5
"Rob" <ro***@yahoo.comschrieb:
For example, how could you programatically "click" on a button in a Form ?
If you are talking about other processes: P/invoke + 'SendInput'.

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

Sep 29 '08 #6
Rob,

Why would you use an event when you can direct invoke the method?

\\\
Button_ClickEvent(me,nothing)
///

This works as well as the button has not the focus.

Cor

"Rob" <ro***@yahoo.comschreef in bericht
news:68******************************@comcast.com. ..
For example, how could you programatically "click" on a button in a Form ?
Sep 30 '08 #7
Cor Ligthert[MVP] wrote:
Why would you use an event when you can direct invoke the method?
Button_ClickEvent(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.
Sep 30 '08 #8
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:gb**********@south.jnrs.ja.net...
Cor Ligthert[MVP] wrote:
>Why would you use an event when you can direct invoke the method?
> Button_ClickEvent(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.
Sep 30 '08 #9
On 2008-09-29, Rob <ro***@yahoo.comwrote:
For example, how could you programatically "click" on a button in a Form ?

Can you be more specific? Are you talking about a form in your application or
in another applciation? In otherwords, cross process or same process?

--
Tom Shelton
Sep 30 '08 #10
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschrieb:
>Why would you use an event when you can direct invoke the method?
> Button_ClickEvent(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.
I agree. It fulfills the contract of the event. Nevertheless, I would not
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/>

Oct 1 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3116
by: jy2003 | last post by:
1. Does MyISAM support FOREIGN KEY constraints? When I read the online MySQL Reference Manual, it said "InnoDB also supports FOREIGN KEY constraints". Does it mean MyISAM does not support FOREIGN...
2
6228
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
30977
by: Gary | last post by:
Hi, I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)") This is not working ..what could be the...
8
14237
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node...
10
9407
by: ucasesoftware | last post by:
In my mainMenu i have items Copy, cut, paste... I have a form with a lot of textbox In my sub of item copy i have : SendKeys.Send("^c") but if the user select a text in a textbox... click...
8
9451
by: Nick | last post by:
I have a table with columns (product_id,related_product_id,related_counter) If product A is related to product B then a record should be created, if the record already exists then the...
0
1475
by: bruce | last post by:
I'm testing a very simple web services called Add (take 2 integers and return the result). The service program is done in VS.NET and work well using HTTP POST. I wrote a simple (Classic) ASP SOAP...
2
1333
by: Stagnight1 | last post by:
Is there a way to define a key that puts the text 'SELECT * FROM ' into the Query Analyzer window? I must type this about 50 times a day but cannot see a simple way of defining a key to write it...
2
6938
by: wpollans | last post by:
Hello, I need to able to write JS that will click on a link with the middle mouse button - so that the link target will open in a new window or tab - using firefox. Or is there a better (more...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.