473,714 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Consuming the KeyDown Event?

Hello

Thanks for reviewing my question. I am trying to consume the Keydown event of the Cntrl-shift-E in a textbox and have noticed that when I press key this combination a beep is made even though the event works correctly? How can I get rid of this beep? I thought that setting the e.Handled to true would do it but no luck

private void txtbxEmail_KeyD own(object sender, System.Windows. Forms.KeyEventA rgs e

if ( (e.KeyCode == Keys.E) && (e.Control) && (e.Shift)

if ( txtbxHomeEmail. Text.Length > 0

System.Diagnost ics.Process.Sta rt("MAILTO:"+tx tbxHomeEmail.Te xt)
e.Handled = true


Many Thank
Peter
Nov 16 '05 #1
2 7025
Peter
Have you tried this on another machine with a different keyboard.?

Perhaps it is keyboard feature (Special Keyboard) that does the beep and not
the key down. Try shutting down any resident keyboard programs or another
machine with a different keyboard than yours.

Henk
"Peter" <an*******@disc ussions.microso ft.com> wrote in message
news:E5******** *************** ***********@mic rosoft.com...
Hello,

Thanks for reviewing my question. I am trying to consume the Keydown event of the Cntrl-shift-E in a textbox and have noticed that when I press
key this combination a beep is made even though the event works correctly?
How can I get rid of this beep? I thought that setting the e.Handled to
true would do it but no luck.
private void txtbxEmail_KeyD own(object sender, System.Windows. Forms.KeyEventA rgs e) {
if ( (e.KeyCode == Keys.E) && (e.Control) && (e.Shift) )
{
if ( txtbxHomeEmail. Text.Length > 0 )
{
System.Diagnost ics.Process.Sta rt("MAILTO:"+tx tbxHomeEmail.Te xt); e.Handled = true;
}
}
}

Many Thanks
Peter

Nov 16 '05 #2
Hi Peter,

The beep is made by the DefWindowProc for keys which is not handled by the
text box. Your code doesn't work because beep is produced in responce to
WM_CHAR (KeyPress), I believe. However you have options.
1. you can override TextBox and its WndProc method and process WM_CHAR
message without passing it to the DefWindowProc
-or-
2. Add a main menu item (it can be hidden) with shortcut for Ctrl+Shift+E
and handle the key press there. You should check the focused control if you
want to react on this combination only for the text box. The downside is
that you always swallow this key combination.
-or-
3. Handle KeyPress instead of key down. e.Handled works for this event. For
Ctrl+Shift+E key press is fired only for Ctrl+E (ASCII 5) so, you have to
chack for Shift yourself. KeyPressEventAr gs doesn't have the key modifiers
that's why probably you should use Control.Modifie rKeys to check for Shift.
The code could be something like

private void textBox2_KeyPre ss(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
if ( e.KeyChar == 5 && (ModifierKeys & Keys.Shift) != 0)
{
if ( textBox2.Text.L ength > 0 )
{
Console.WriteLi ne("Handled in keydown");
e.Handled = true;

}
}
}
--

HTH
Stoitcho Goutsev (100) [C# MVP]
"Peter" <an*******@disc ussions.microso ft.com> wrote in message
news:E5******** *************** ***********@mic rosoft.com...
Hello,

Thanks for reviewing my question. I am trying to consume the Keydown event of the Cntrl-shift-E in a textbox and have noticed that when I press
key this combination a beep is made even though the event works correctly?
How can I get rid of this beep? I thought that setting the e.Handled to
true would do it but no luck.
private void txtbxEmail_KeyD own(object sender, System.Windows. Forms.KeyEventA rgs e) {
if ( (e.KeyCode == Keys.E) && (e.Control) && (e.Shift) )
{
if ( txtbxHomeEmail. Text.Length > 0 )
{
System.Diagnost ics.Process.Sta rt("MAILTO:"+tx tbxHomeEmail.Te xt); e.Handled = true;
}
}
}

Many Thanks
Peter

Nov 16 '05 #3

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

Similar topics

3
9227
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I click on a row (withs will turn blue then) and then click on it again . Now if I press any key the event will fire (except for the arrow keys). I also tried to override the IsInputKey => no luck. I also tried to override the ProcessCmdKey => With...
4
13115
by: Tony | last post by:
I'm building a simple "breakout" style video-game, and I want keyboard control of the paddle. What I need is for an event handler to respond whenever a key is pressed, regardless of what the focus is set to. So far, the best I've been able to accomplish is to create a button and have that button handle the KeyDown event. I've tried using KeyDown on the form, but it simply doesn't work. I did a search on this, and found on site that...
4
8634
by: Anne | last post by:
hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private Sub txtRequestor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRequestor.KeyDown If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
4
7128
by: ShaneO | last post by:
I would like to handle the KeyUp & KeyDown events in the same event handler but can't find how to determine which event was fired - Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles ListBox1.KeyUp, ListBox1.KeyDown If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue = Keys.End Or e.KeyValue = Keys.Home Then
1
3306
by: fripper | last post by:
I have a VB 2005 windows app and I want to recognize keydown events. I have a form key down event handler but it does not get control when a key is depressed. In playing around I found that if I add a keydown event handler for some control on the form, say a textbox ... Private Sub txtBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBox.KeyDown) and then give that control focus the keydown...
0
1753
by: tony | last post by:
Hello!! I have a derived class called StringClassEditor which inherit from UITypeEditor listed below. Now to my question in method EditValue in this class I have this statement lb.KeyDown += new KeyEventHandler(ListBox_KeyDown); I have set a breakpoint in the event handler method ListBox_KeyDown but this method is never called. So this event KeyDown for control ListBox is never occuring.
3
4301
by: win | last post by:
when the cursor is in a textbox, only coding in the keydown event of the textbox triggered, the coding in the keydown event of the form does not triggered! Problem: I need to change a VB6 program to .Net. It uses function key(e.g. F12) to close the form, now i need to write the coding in the keydown event of all controls form. Can anyone help me? Thanks a lot.
2
19293
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
14
2969
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main reason you would want to do this is for example to trigger something from an OnPaint event without resorting to boolean switches-- say if a user presses the "M" key while the program is Painting, the user gets the PaintHandler to do something else. ...
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9077
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6637
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4727
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3159
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 we have to send another system
2
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.