在edit中新增FCharCase属性,实现首字母的选择(100分)

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设置为大写的时候,
不能实现预定的首字母大写,其余小写的效果
 
试试在keydown里写代码,直接替换key的值!
 
不行啊,我怀疑是跟delphi原来的charcase有冲突,但由于本人学delphi不久,
不能对这些vcl进行深入分析,那高手出马,帮忙啊
 

Similar threads

I
回复
0
查看
727
import
I
顶部