我做了2个 Demo
第一个:建立一个form 放上一个lable 然后设置 form 的keypreview为true
然后在form的keypress事件中写label1.caption:=key第二个:建立一个form 放上一个label ,一个edit然后设置 form 的keypreview为true
然后在form的keypress事件中写label1.caption:=key
------------------------------
运行以后,我在第一个窗体上 打汉字,label可以显示出来但是在第二个窗体的edit 中 打汉字,label显示的就不对了,原因是 在edit里面输入后 每两个全角字符变成一个key值
如:我在edit里面写 中国 label上显示的却是 止这个问题怎么解决?????PS:键入半角英文没有问题
第一个:建立一个form 放上一个lable 然后设置 form 的keypreview为true
然后在form的keypress事件中写label1.caption:=key第二个:建立一个form 放上一个label ,一个edit然后设置 form 的keypreview为true
然后在form的keypress事件中写label1.caption:=key
------------------------------
运行以后,我在第一个窗体上 打汉字,label可以显示出来但是在第二个窗体的edit 中 打汉字,label显示的就不对了,原因是 在edit里面输入后 每两个全角字符变成一个key值
如:我在edit里面写 中国 label上显示的却是 止这个问题怎么解决?????PS:键入半角英文没有问题
我按照你的方法一个都没有实现!
不就行了?
二楼说的非常正确。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
kstr:string;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
exit;
if (key=#8) then
begin
if length(kstr)>0 then
begin
if kstr[length(kstr)]>#128 then
kstr:=copy(kstr,1,length(kstr)-2)
else
kstr:=copy(kstr,1,length(kstr)-1)
end
end
else
kstr:=kstr+key; label1.Caption:=kstr;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
kstr:=''
end;end.