By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,114 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,114 IT Pros & Developers. It's quick & easy.

Generating or simulating key events sent to control on form

P: n/a
Hi Everyone,

Is there a way of generating a keyboard character event and sending it to a
control on a form? For example, if I have a menu item called "Delete", I
would like to send a DEL character event to the currently active control on
the form.

Thanks.
Feb 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Sorry, I forgot to mention that this is for VB.NET 2003.

- Ivan

"Bill J" <Bi***@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Everyone,

Is there a way of generating a keyboard character event and sending it to a
control on a form? For example, if I have a menu item called "Delete", I
would like to send a DEL character event to the currently active control on
the form.

Thanks.

Feb 17 '06 #2

P: n/a
Hi Ivan,
Is there a way of generating a keyboard character event
and sending it to a control on a form?


Have you tried the System.Windows.Forms.SendKeys class?

I suggest you can set the focus to the target control first, then call the
System.Windows.Forms.SendKeys.Send method to send the keystroke, such as:

Control1.Focus()
System.Windows.Forms.SendKeys.Send("{DEL}")

Please refer to the following MSDN documentation for the details:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformssendkeysclasstopic.asp
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
================================================== ====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====

Feb 17 '06 #3

P: n/a
Hi Gary,

Thank you very much. It works like a charm. Cut, copy, paste also work
based on the control key sequences (eg "^C" for copy). However, I am not
able to get Select All to work. The "^A" sequence does not have any effect.
Is there a special command for this in a simple edit control?
""Gary Chang[MSFT]"" <v-******@online.microsoft.com> wrote in message
news:0C**************@TK2MSFTNGXA01.phx.gbl...
Hi Ivan,
Is there a way of generating a keyboard character event
and sending it to a control on a form?


Have you tried the System.Windows.Forms.SendKeys class?

I suggest you can set the focus to the target control first, then call the
System.Windows.Forms.SendKeys.Send method to send the keystroke, such as:

Control1.Focus()
System.Windows.Forms.SendKeys.Send("{DEL}")

Please refer to the following MSDN documentation for the details:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformssendkeysclasstopic.asp
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
================================================== ====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====
Feb 17 '06 #4

P: n/a
Hi Bill,

I think this is because the TextBox control doesn't have a shortcut for the
Select All operation It doesn't work when you press Ctrl+A on a textbox
control directly neither.

I suggest you can use the SelectAll() method of the textbox control instead:

TextBox1.SelectAll()
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
================================================== ====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====

Feb 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.