procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key in ['a','s']) then Key := #0 end;
要是在keydown事件里怎么处理?
你就是要屏蔽一些键的输入对吧? meiqingsong(阿飛) 的答案是最佳的方法。procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key in ['a'..'z','A'..'Z']) then Key := #0 end;以上是屏蔽了a~-z
粘贴无效,供参考 if ((Key = ord('V')) and (ssCtrl in Shift)) then begin if Clipboard.HasFormat(CF_TEXT) then ClipBoard.Clear; key := 0; end;
以上是屏蔽了a-z和A-Z的输入,其他的你可以类似的做一些东西
要是在keydown事件里怎么处理?
procedure TGetBillFrm.EdtBillBKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var sz:array[0..5] of char; begin sz[0] := #0; if (Key in [Integer('a')..Integer('z'),Integer('A')..Integer('Z')]) then // PostMessage(EdtBillB.Handle, WM_SETTEXT, 0, Integer(@sz)); SetWindowText(EdtBillB.Handle, #0); // Key := Integer(#0); // Key := 0; ShowMessage(IntToStr(Low(Key)) + ' ' + IntToStr(High(Key)) + ' ' + IntToStr(Key)); end;在OnKeyDown 试了三种方法都不行 中午有空再看看
uses Qt;procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key in[key_A..Key_Z,KEY_a..key_z]) then Key := 0 end; 屏蔽了a-z和A-Z的输入
sorry 上面的还是没效果
procedure TForm1.Edit1Change(Sender: TObject); var str:string; i:integer; begin str:=edit1.Text; for i:=1 to length(str) do begin if str[i] in ['a','b','m'] then begin edit1.Text:=copy(str,1,i-1); edit1.SelStart:=i; exit; end; end; end;
begin
if (Key in ['a','s']) then
Key := #0
end;
begin
if (Key in ['a'..'z','A'..'Z']) then
Key := #0
end;以上是屏蔽了a~-z
if ((Key = ord('V')) and (ssCtrl in Shift)) then
begin
if Clipboard.HasFormat(CF_TEXT) then
ClipBoard.Clear;
key := 0;
end;
Shift: TShiftState);
var
sz:array[0..5] of char;
begin
sz[0] := #0;
if (Key in [Integer('a')..Integer('z'),Integer('A')..Integer('Z')]) then
// PostMessage(EdtBillB.Handle, WM_SETTEXT, 0, Integer(@sz));
SetWindowText(EdtBillB.Handle, #0);
// Key := Integer(#0);
// Key := 0;
ShowMessage(IntToStr(Low(Key)) + ' ' + IntToStr(High(Key)) + ' ' + IntToStr(Key));
end;在OnKeyDown 试了三种方法都不行 中午有空再看看
可以拉一空PopMenu,然后使该Edit的PopupMenu属性指向该空PopMenu即可
Shift: TShiftState);
begin
if (Key in[key_A..Key_Z,KEY_a..key_z]) then
Key := 0
end;
屏蔽了a-z和A-Z的输入
上面的还是没效果
var str:string;
i:integer;
begin
str:=edit1.Text;
for i:=1 to length(str) do
begin
if str[i] in ['a','b','m'] then
begin
edit1.Text:=copy(str,1,i-1);
edit1.SelStart:=i;
exit;
end;
end;
end;