问题
How can I change the TEdit's default error message when I use it in NumbersOnly mode. I mean this error:
Unacceptable character You can only type a number here
Is it possible to change this message ?
回答1:
I don't know a direct way to change the value of that message (which is handled by Windows) but you can show your own message and then avoid to show the original windows hint ballon, using the Abort procedure in the OnKeyPress Event.
Check this sample
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (CharInSet(Key,['0'..'9',#8,#9])) then
begin
ShowHintMessage('Only numbers please');//you must write this function
Abort;//this will prevent which the original windows hint was shown
end;
end;
You must we aware which this code will be prevent the execution of the clipboard operations over the control.
Update
I Update the code to allow the Tab(#9) and Back space(#8) chars.
回答2:
Looking at the VCL source, it looks like that message is generated by windows, rather than by Delphi. That is, the VCL is only wrapping the functionality that exists in windows. So it doesn't appear that it would be easy to modify the message.
来源:https://stackoverflow.com/questions/6896870/how-can-i-change-the-tedit-default-error-message-numbersonly-mode