Board index » delphi » Delphi TEdit: How do I stop it beeping?

Delphi TEdit: How do I stop it beeping?

Consider this trivial example:

I have a TEdit control and I want the user to enter a text string
which is delimited by the Enter key.

I write a KeyPress handler as follows:

if Key = Chr(13) then  {check for the Enter key}
  MyLabel.Caption := MyEdit.Text;

This works, but each time I press the Enter key, I get a beep
occurring. From BP7 days I seem to remember that this is caused by
some sort of default Windows behavior, but I can't remember how to
override it. Can anyone help?

Craig Findlay <cfind...@netspace.net.au>
Melbourne, Australia

 

Re:Delphi TEdit: How do I stop it beeping?


Quote
Craig Findlay (cfind...@netspace.net.au) wrote:

: Consider this trivial example:

: I have a TEdit control and I want the user to enter a text string
: which is delimited by the Enter key.

: I write a KeyPress handler as follows:

: if Key = Chr(13) then  {check for the Enter key}
:   MyLabel.Caption := MyEdit.Text;

: This works, but each time I press the Enter key, I get a beep
: occurring. From BP7 days I seem to remember that this is caused by
: some sort of default Windows behavior, but I can't remember how to
: override it. Can anyone help?

: Craig Findlay <cfind...@netspace.net.au>
: Melbourne, Australia

I got around it this way:  Set KeyPreview := True for the form and capture
the enter key in the OnKeyPress form event, if the sender is the editbox,
you now can process the return and change it to something else like
null before the editbox sees it.

Hope this helps,

Robert Wahler
rwah...@is.net

Other Threads