Mega Code Archive

 
Categories / Delphi / Multimedia
 

Using Enter Key Without Sound (Revised Code)

Title: Using Enter Key Without Sound (Revised Code) Question: How to prevent the beep sound generated by windows when using Enter key as Tab on TEdit control. Answer: This is a revised code previously presented in the article 'Using Enter Key' at http://www.delphi3000.com/articles/article_1681.asp The new code is aimed to prevent the beep sound generated by windows when using Enter key on TEdit control, Note: If you are new to Delphi please note that the first procedure below must entered manually along with its corresponding declaration in the form class. procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char); begin if key = #13 then key := #0; end; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var ACtrl: TWinControl; k: TKeyPressEvent; begin if key = 13 then begin ACtrl := ActiveControl; if ACtrl is TCustomMemo then exit; if ACtrl is TEdit then begin if assigned(TEdit(ACtrl).onKeyPress) then k:= TEdit(ACtrl).OnKeyPress; TEdit(ACtrl).OnKeyPress := EditKeyPress; end; repeat ACtrl:= FindNextControl(ACtrl,true,true,false); until (ACtrl is TCustomEdit) or (ACtrl is TCustomComboBox) or (ACtrl is TCustomListBox) or (ACtrl is TCustomCheckBox) or (ACtrl is TRadioButton); if ACtrl is TEdit then begin if assigned(K) then TEdit(ACtrl).OnKeyPress := K; end; ACtrl.SetFocus ; end; end;