|
-
Apr 30th, 2004, 11:28 PM
#1
Thread Starter
Junior Member
Avoiding beep when pressing ENTER in a textbox.
I'm looking for a way to avoid that nasty *beep* you get every time you press the ENTER key in a textbox / combobox. I found this code in the VB section but don't know how to translate it:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
KeyAscii = 0 ' "Eat" the tab to avoid the beep
RestoreTabStops Text1
End If
End Sub
In this example its a TAB but in my case it's an ENTER. I can't translate it cuz the e.KeyChar value returned by KeyPress on C# cannot be modified like you can in VB.
Can anyone tell me how to accomplish this? Thanks!
-
Apr 30th, 2004, 11:49 PM
#2
Frenzied Member
Code:
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
ProcessDialogKey(e.KeyCode);
}
protected override bool ProcessDialogKey(System.Windows.Forms.Keys keyData)
{
System.Windows.Forms.Keys key = keyData;
if(key == System.Windows.Forms.Keys.Enter)
{
return true;
}
return base.ProcessDialogKey(keyData);
}
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
May 1st, 2004, 03:50 PM
#3
no need though for a sub to handle the beep ( ie: preventing it )
this is all thats needed ...
VB Code:
[color=blue]private void[/color] textBox1_KeyPress([color=blue]object[/color] sender, System.Windows.Forms.KeyPressEventArgs e)
{
[color=blue]if[/color](e.KeyChar == ([color=blue]char[/color])Keys.Enter)
{
e.Handled=[color=blue]true[/color];
}
}
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
May 2nd, 2004, 11:54 PM
#4
Thread Starter
Junior Member
Ok, I tried it in a textbox and it works. I also need it to work on a combobox but it *doesnt* seem to work. What needs to be done to make it work in a combo as well?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|