Results 1 to 4 of 4

Thread: Avoiding beep when pressing ENTER in a textbox.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    30

    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!

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    no need though for a sub to handle the beep ( ie: preventing it )
    this is all thats needed ...
    VB Code:
    1. [color=blue]private void[/color] textBox1_KeyPress([color=blue]object[/color] sender, System.Windows.Forms.KeyPressEventArgs e)
    2.         {
    3.             [color=blue]if[/color](e.KeyChar == ([color=blue]char[/color])Keys.Enter)
    4.             {
    5.                 e.Handled=[color=blue]true[/color];
    6.             }
    7.         }
    ~
    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]

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    30
    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
  •  



Click Here to Expand Forum to Full Width