看看spinedit控件的代码吧! function TSpinEdit.IsValidChar(Key: Char): Boolean; begin Result := (Key in [DecimalSeparator, '+', '-', '0'..'9']) or ((Key < #32) and (Key <> Chr(VK_RETURN))); if not FEditorEnabled and Result and ((Key >= #32) or (Key = Char(VK_BACK)) or (Key = Char(VK_DELETE))) then Result := False; end;
先谢谢大家了。在keydown中我实现了TAB功能,但是系统会beep,如何将声音去掉,能不能重载TSpinEdit.IsValidChar函数。 procedure TfrmBKHKML.spinYearKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (key=13) then begin key:=0; perform(CM_Dialogkey,VK_TAB,0); end; end;
其实,你把 function TSpinEdit.IsValidChar(Key: Char): Boolean; begin Result := (Key in [DecimalSeparator, '+', '-', '0'..'9']) or ((Key < #32) and (Key <> Chr(VK_RETURN)));//改为 key = Chr(VK_RETURN) 即可响应onkeypress,系统也不会beep if not FEditorEnabled and Result and ((Key >= #32) or (Key = Char(VK_BACK)) or (Key = Char(VK_DELETE))) then Result := False; end;
function TSpinEdit.IsValidChar(Key: Char): Boolean;
begin
Result := (Key in [DecimalSeparator, '+', '-', '0'..'9']) or
((Key < #32) and (Key <> Chr(VK_RETURN)));
if not FEditorEnabled and Result and ((Key >= #32) or
(Key = Char(VK_BACK)) or (Key = Char(VK_DELETE))) then
Result := False;
end;
在OnKeyDown事件中key的类型为word,该如何将char转换为word!
procedure TfrmBKHKML.spinYearKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=13) then
begin
key:=0;
perform(CM_Dialogkey,VK_TAB,0);
end;
end;
function TSpinEdit.IsValidChar(Key: Char): Boolean;
begin
Result := (Key in [DecimalSeparator, '+', '-', '0'..'9']) or
((Key < #32) and (Key <> Chr(VK_RETURN)));//改为 key = Chr(VK_RETURN) 即可响应onkeypress,系统也不会beep
if not FEditorEnabled and Result and ((Key >= #32) or
(Key = Char(VK_BACK)) or (Key = Char(VK_DELETE))) then
Result := False;
end;
请问应在什么地方声明。