delphi中的edit输入数字时怎样显示千分位
1个回答
展开全部
EDIT本身没有这个功能,可以变通一点,设置edit右对齐,然后每次输入后把光标移动到最左则,然后通过KeyPress控制只允许输出数字,代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
chargerstyle:integer;
begin
chargerstyle:=GetWindowLong(remark.Handle,GWL_STYLE);
chargerstyle:=chargerstyle and(not ES_LEFT)and(not ES_CENTER)or ES_RIGHT;
SetWindowLong(remark.Handle,GWL_STYLE,chargerstyle);
end;
procedure TForm1.remarkKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in['0'..'9',#8]) then begin
key:=#0;
end;
end;
procedure TForm1.remarkChange(Sender: TObject);
begin
remark.SelStart:=0;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
chargerstyle:integer;
begin
chargerstyle:=GetWindowLong(remark.Handle,GWL_STYLE);
chargerstyle:=chargerstyle and(not ES_LEFT)and(not ES_CENTER)or ES_RIGHT;
SetWindowLong(remark.Handle,GWL_STYLE,chargerstyle);
end;
procedure TForm1.remarkKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in['0'..'9',#8]) then begin
key:=#0;
end;
end;
procedure TForm1.remarkChange(Sender: TObject);
begin
remark.SelStart:=0;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询