大家好,在此我有个问题想请教。请各位帮下忙 (50分)

  • 主题发起人 yuan2705
  • 开始时间
Y

yuan2705

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI6中我做一个简单的打字练习,遇到了一个问题想请教各位:在打错字时字体变成
另一种颜色而对的不变,这个代码应该怎样写?以下是我原本的代码
procedure TMainForm.RichEdit2Change(Sender: TObject);
var
I:Integer;
begin
Y:=0;
N:=0;
srzs.Caption:='0';
//输入字数
szdf.Caption:='0';
//得分现在
jczs.Caption:='0';
//正确字数
cwzs.Caption:='0';
//错误字数
srzs.Caption:=IntToStr(Length(RichEdit2.Text));
//输入字数
RichEdit1.SelectAll;
RichEdit1.SelAttributes.Color:=clBlack ;
RichEdit1.SelStart:=0;
RichEdit1.SelLength:= Length(RichEdit2.Text);
RichEdit1.SelAttributes.Color:=clRed ;
RichEdit1.SelStart :=clBlack-1;
RichEdit1.SelLength := 0;
RichEdit1.SelAttributes.Color := clBackground;
for I:= 1 to Length(RichEdit2.Text)do
begin
if copy(RichEdit1.Text,I,1) = copy(RichEdit2.Text,I,1) then
Y:=Y+1 else
N:=N+1 ;
jczs.Caption:=IntTostr(Y);
//正确字数
cwzs.Caption:=IntTostr(N);
//错误字数
szdf.Caption:=IntTostr(Length(RichEdit2.Text)-5*N);
//现在得分
end;
end;
 
先判断对错呀!
 
先判断对错,另外也不要有错误就把所有字都变色啊
 
不能直接用Label,因为它不能单独控制某个字的颜色
你可以在Canvas上用TextOut自己画[:D]
 
可以考虑用RichText
 
你用什么做的,放在什么控件上的???
 
RichText能实现单个字变色。
 
在richtext控件中用select 方法选中错误的字母,再改变其颜色.
 
procedure TForm1.RichEdit2KeyPress(Sender: TObject;
var Key: Char);
var
sc: string;
l: integer;
begin
l:= Length(RichEdit1.Text)-2;
RichEdit1.SelStart:= icount;
RichEdit1.SelLength:=1;
sc:= RichEdit1.SelText;
if icount < l then
begin
if Ord(Key) <> Ord(sc[1]) then
begin
with RichEdit1.SelAttributesdo
begin
Color := clRed;
fc:= fc + 1;
Edit4.Text:= IntToStr(fc);
end;
end
else
begin
with RichEdit1.SelAttributesdo
begin
Color := clBlue;
tc:= tc + 1;
Edit3.Text:= IntToStr(tc);
Edit2.Text:= IntTostr(Length(RichEdit2.Text)-5*tc);
end;
end;
icount:= icount + 1;
Edit1.Text:= IntToStr(icount);
end
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
2K
import
I
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部