C
crq
Unregistered / Unconfirmed
GUEST, unregistred user!
type
TExtEdit = class(TEdit)
private
FFirstCharCase : TEditCharCase;
protected
procedure SetFirstCharCase(value: TEditCharCase);
published
property FirstCharCase : TEditCharCase read FFirstCharCase write SetFirstCharCase default ecNormal;
end;
procedure TExtEdit.KeyPress(var Key: Char);
begin
inherited;
if (Length(Text)=0) or ((Length(Text)>0) and (SelStart=0)) then
begin
if (FFirstCharCase=ecUpperCase) and (Ord(Key)>=97) and (Ord(Key)<=122) then
begin
Text:=UpperCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
Key:=UpperCase(Key)[1];
end
else if (FFirstCharCase=ecLowerCase) and (Ord(Key)>=65) and (Ord(Key)<=90) then
begin
Text:=LowerCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
Key:=LowerCase(Key)[1];
end;
end;
end;
procedure TExtEdit.SetFirstCharCase(value: TEditCharCase);
begin
if (value <> FFirstCharCase) then
begin
if value=ecUpperCase then
Text:=UpperCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1)
else if value=ecLowerCase then
Text:=LowerCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
FFirstCharCase:=value;
RecreateWnd;
end;
end;
当原有的Charcase设置为小写,Fcharcase设置为大写的时候,
不能实现预定的首字母大写,其余小写的效果
TExtEdit = class(TEdit)
private
FFirstCharCase : TEditCharCase;
protected
procedure SetFirstCharCase(value: TEditCharCase);
published
property FirstCharCase : TEditCharCase read FFirstCharCase write SetFirstCharCase default ecNormal;
end;
procedure TExtEdit.KeyPress(var Key: Char);
begin
inherited;
if (Length(Text)=0) or ((Length(Text)>0) and (SelStart=0)) then
begin
if (FFirstCharCase=ecUpperCase) and (Ord(Key)>=97) and (Ord(Key)<=122) then
begin
Text:=UpperCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
Key:=UpperCase(Key)[1];
end
else if (FFirstCharCase=ecLowerCase) and (Ord(Key)>=65) and (Ord(Key)<=90) then
begin
Text:=LowerCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
Key:=LowerCase(Key)[1];
end;
end;
end;
procedure TExtEdit.SetFirstCharCase(value: TEditCharCase);
begin
if (value <> FFirstCharCase) then
begin
if value=ecUpperCase then
Text:=UpperCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1)
else if value=ecLowerCase then
Text:=LowerCase(Copy(Text,1,1))+Copy(Text,2,Length(Text) -1);
FFirstCharCase:=value;
RecreateWnd;
end;
end;
当原有的Charcase设置为小写,Fcharcase设置为大写的时候,
不能实现预定的首字母大写,其余小写的效果