Cameron Kloot

hi,
how would i be able to make a textbox not have the beep when bad chars are imputed even with the accepts return option, it doesnt get rid of it. would the same method work for a combo box
thanks




Re: Visual C# Express Edition text box invalid char beep

ahmedilyas

I believe this is all down to the environment configuration of the system itself and how Windows responds to such events. I'm not sure you can control about disabling the beep. If I find anything, or im sure someone else may well know, will be sure to post :-)






Re: Visual C# Express Edition text box invalid char beep

Ken_L

It not even that hard; You can prevent the beep when the enter key is pressed in a TextBox by deriving the TextBox and overriding OnKeyPress.

You can do something like this

Code Snippet

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)

{

if (e.KeyChar == (char)13)

{

e.Handled = true;

}

else

{

base.OnKeyPress(e);

}

}

I imagine you could add the char value of the rest of the keys that are causing your beep....






Re: Visual C# Express Edition text box invalid char beep

ahmedilyas

Good find - forgot about that! :-)






Re: Visual C# Express Edition text box invalid char beep

nobugz

If you want the Enter key to do something useful, paste this code into your form:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Enter && this.AcceptButton == null) {
TextBoxBase box = this.ActiveControl as TextBoxBase;
if (box == null || !box.Multiline) return this.ProcessDialogKey(Keys.Tab);
}
return base.ProcessCmdKey(ref msg, keyData);
}





Re: Visual C# Express Edition text box invalid char beep

Gunta987

You're a champion nobugz!
replace this.ProcessDialogKey(Keys.Tab); with whatever functionality you need and the previously annoying beep is gone Smile