我的是这样写的
给你参考。
procedure TAnteListGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
var
s : string;
tmpR : Trect;
R3, R1, R0: TRect;
iR3,iR1,iR0: TRect;
btnRect : TRect;
EditRect : Trect;
BARect : TRect;
GbtnRect : TRect;
GEditRect : TRect;
oldColor : TColor;
FontColor : Tcolor;
SltColor : TColor;
Sg3Color : Tcolor;
Sg1Color : TColor;
Sg0Color : Tcolor;
Function needDrwX(str: string): boolean;
var
c,sc: char;
begin
c:=FResult[ARow];
if str='' then result:=false
else begin
sc:=str[1];
result:=(C in ['3','1','0']) and (sc in ['3','1','0'])
and (C<>sc) ;
end;
end;
begin
S:=cells[ACol,ARow];
with FBufferBmp do begin
Height:=ARect.Bottom-ARect.Top;
Width:=Arect.Right-ARect.Left;
BARect:=Rect(0,0,Width,Height);
Canvas.Font:=Font;
SplitRect(Acol, BARect,editRect,btnRect);
end;
SplitRect(Acol,ARect,GeditRect,GbtnRect);
// setColors....
if ACol>3 then
if FCrUser=cells[ACol,14] then begin
Fontcolor:=clBlack;
sltColor:=clBlack;
Sg3Color:=clLime;
Sg1Color:=clAqua;
Sg0Color:=clYellow;
end else begin
FontColor:=clGray;
sltColor:=getAlphaColor(clBlack,clWhite,156);
Sg3Color:=getAlphaColor(clLime,clWhite,156);
Sg1Color:=getAlphaColor(clAqua,clWhite,156);
Sg0Color:=getAlphaColor(clYellow,clWhite,156);
end;
with FBufferBmp.Canvas.Brush, FBufferBmp.Canvas do begin
if ARow in [0..14] then Color:=TeamRows.Items[ARow].Color;
if ACol=0 then Color:=getalphacolor(Color,clBlack,64);
if ACol=2 then Color:=getalphacolor(Color,clblack,20);
if ACol in [1,3] then Color:=getalphacolor(Color,clYellow,12);
if (ACol>3) then if (ACol mod 2>0) then
Color:=getalphacolor(Color,clWhite,20)
else
Color:=getalphacolor(Color,clBlack,20);
if (ColWidths[ACol-1]=0) and (ColWidths[ACol-1] mod 2=0)
then Color:=getalphacolor(Color,clYellow,20);
if calHitCount(ACol)='13' then Color:=getAlphaColor(Color,clRed,32);
if calHitCount(ACol)='12' then Color:=getAlphaColor(Color,clYellow,64);
if calHitCount(ACol)='11' then Color:=getAlphaColor(Color,clGreen,64);
if Cells[ACol,15]='1' then Color:=getalphacolor(Color,clBlue,48);
if (ACol=Col) and (ARow=0) then Color:=getalphacolor(clWhite,clLime,128);
FillRect(BARect);
Pen.Color:=clGray; //Rui
pen.Width:=1;
if (FCrnMouseInCol=ACol) and (FCrnMouseInRow=ARow) and FAllowEdit and
(not isEditCell(ACol,ARow)) then begin
if (ACol in [1..3]) and (ARow in [1..13]) then begin
Color:=getAlphaColor(Color,clBlue,48);
Rectangle(BARect);
end;
if ((ACol>3) and (ARow=0)) then begin
Color:=getAlphaColor(clWhite,Color,80);
if AllowEdit then begin
Rectangle(BARect);
if hasSgcolS(ACol) or (ColWidths[Acol] in [epSGCOLW,SGCOLW])
then rectangle(btnRect);
end;
end;
end;
if isEditCell(Acol,ARow) then begin
Color:=clWhite;
Style:=bsSolid;
if ColhasMark(Acol)and (ARow=0) then
Rectangle(EditRect)
else begin
Rectangle(BARect);
inflateRect(btnRect,-1,-2);
Color:=clBtnFace;
fillRect(btnRect);
if Acol in[1,3] then DrawDownArraw(FBufferBmp.Canvas,btnRect,3,clBlack);
end;
end;
if (ACol>3) and (ARow=0) then begin
Color:=getAlphaColor(clWhite,Color,80);
if hasSgcols(ACol) then
if ColWidths[ACol+1]>0 then begin
if ptInRect(GBtnRect,HitTest) then begin
Rectangle(btnRect);
DrawTriAngleMark(FBufferBmp.Canvas,btnRect,clBlue,4,'LEFT',not FmouseDown);
end
else DrawTriAngleMark(FBufferBmp.Canvas,btnRect,clBlack,4,'LEFT',False);
end
else if ptInRect(GBtnRect,HitTest) then begin
Rectangle(btnRect);
DrawTriAngleMark(FBufferBmp.Canvas,btnRect,clBlue,4,'Right',not FmouseDown);
end
else DrawTriAngleMark(FBufferBmp.Canvas,btnRect,clBlack,4,'Right',false);
//draw single triangle mark;
tmpR:=BtnRect;
offsetRect(tmpR,0,(BARect.Bottom-BARect.Top-6) div 2);
if colWidths[Acol] = epSGCOLW then begin
if ptInRect(GBtnRect,{FCursorPos}HitTest) then begin
Rectangle(btnRect);
DrawTriAngleMark(FBufferBmp.Canvas,tmpR,clBlue,4,'LEFT',not FmouseDown);
end
else DrawTriAngleMark(FBufferBmp.Canvas,tmpR,clBlack,4,'LEFT',false);
end
else if colWidths[Acol]=SGCOLW then
if ptInRect(GBtnRect,{FCursorPos}HitTest) then begin
Rectangle(btnRect);
DrawTriAngleMark(FBufferBmp.Canvas,tmpR,clBlue,4,'Right',not FmouseDown);
end
else DrawTriAngleMark(FBufferBmp.Canvas,tmpR,clBlack,4,'Right',false);
end;
FResult:=getResult;
// paint compound selecttions
if (ColWidths[ACol]=epCMPCOLW) and (ARow in [1..13]) then begin
tmpR:=BARect;
inflateRect(tmpR,-(BARect.Right-BARect.Left) div 3-SPACE,-1);
R3:=tmpR; R1:=tmpR; R0:=tmpR;
offsetRect(R3,R3.Right-BARect.Right+MARGIN,0);
offsetRect(R0,BARect.Right-R0.Right-MARGIN,0);
iR3:=R3; iR1:=R1; iR0:=R0;
inflateRect(iR3,-3,-2);
inflateRect(iR1,-3,-2);
inflateRect(iR0,-3,-2);
oldColor:=Color;
if pos('3',S)<>0 then begin
Color:=sltColor;
if pos('A',S)<>0 then color:=clBlue;
fillRect(R3);
Font.Color:=clWhite;
end else Font.Color:=FontColor;
if (FsgAnteInCp[ARow]='3') and (Col=ACol) then begin
Color:=clLime;
fillRect(iR3);
Font.Color:=FontColor;
end;
Style:=bsClear;
drawtext(handle,'3',1,R3, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
if pos('1',S)<>0 then begin
Color:=sltColor;
if pos('B',S)<>0 then color:=clBlue;
fillRect(R1);
Font.Color:=clWhite;
end else Font.Color:=FontColor;
if (FsgAnteInCp[ARow]='1') and (Col=ACol) then begin
Color:=clAqua;
fillRect(iR1);
Font.Color:=clBlack;
end;
Style:=bsClear;
drawtext(handle,'1',1,R1, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
if pos('0',S)<>0 then begin
Color:=sltColor;
if pos('C',S)<>0 then color:=clBlue;
fillRect(R0);
Font.Color:=clWhite;
end else Font.Color:=FontColor;
if (FsgAnteInCp[ARow]='0') and (Col=ACol) then begin
Color:=clYellow;
fillRect(iR0);
Font.Color:=clBlack;
end;
Style:=bsClear;
drawtext(handle,'0',1,R0, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
// draw checked marking ........
pen.Width:=2;
Style:=bsSolid;
pen.Color:=clGray;
if FResult[ARow]='3' then drawCheckMark(FBufferBmp.Canvas,R3,2,clRed);
if FResult[ARow]='1' then drawCheckMark(FBufferBmp.Canvas,R1,2,clRed);
if FResult[ARow]='0' then drawCheckMark(FBufferBmp.Canvas,R0,2,clRed);
pen.Width:=1;
Color:=OldColor;
end;
//draw single ante with expanding
if (ColWidths[ACol]=epSGCOLW) and (ARow in [1..13]) then begin
tmpR:=BARect;
inflateRect(tmpR,-(BARect.Right-BARect.Left) div 3-5,-1);
R3:=tmpR; R1:=tmpR; R0:=tmpR;
offsetRect(R3,R3.Right-BARect.Right+MARGIN,0);
offsetRect(R0,BARect.Right-R0.Right-MARGIN,0);
oldColor:=Color;
pen.Color:=clGray; //rui
Font.Color:=FontColor;
if Pos('3', S)<>0 then begin
brush.Color:=Sg3Color;
rectangle(R3);
end;
if Pos('1', S)<>0 then begin
brush.Color:=Sg1Color;
rectangle(R1);
end;
if Pos('0', S)<>0 then begin
brush.Color:=Sg0Color;
rectangle(R0);
end;
brush.Style:=bsClear;
drawtext(handle,'3',1,R3, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
drawtext(handle,'1',1,R1, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
drawtext(handle,'0',1,R0, DT_CENTER or DT_SINGLELINE or DT_VCENTER);
pen.Width:=2;
brush.Style:=bsClear;
if FResult[ARow]='3' then drawCheckMark(FBufferBmp.Canvas,R3,2,clRed);
if FResult[ARow]='1' then drawCheckMark(FBufferBmp.Canvas,R1,2,clRed);
if FResult[ARow]='0' then drawCheckMark(FBufferBmp.Canvas,R0,2,clRed);
pen.Width:=1;
brush.Color:=OldColor;
end;
//draw single ante;
if (ColWidths[ACol]=SGCOLW) and (ARow in [1..13]) then begin
font.Style:=[fsBold];
if s='3' then font.Color:=getAlphacolor(clBlack,FontColor,128);
if s='1' then font.Color:=getAlphacolor(clRed,FontColor,128);
if s='0' then font.Color:=getAlphacolor(clLime,FontColor,128);
drawtext(handle,pchar(S),length(S),BARect, DT_CENTER
or DT_SINGLELINE or DT_VCENTER);
if needDrwX(S) then begin
tmpR:=BARect;
brush.Style:=bsClear;
Pen.Color:=clRed;
Pen.Width:=2;
InflateRect(tmpR,-19,-8);
OffsetRect(tmpR,13,5);
moveto(tmpR.Left,tmpR.Top);
lineTo(tmpR.Right,tmpR.Bottom);
moveTo(tmpR.Right,tmpR.Top);
Lineto(tmpR.Left,tmpR.Bottom);
end;
end;
//draw text
Font.Color:=FontColor;
brush.Style:=bsClear;
if ARow=0 then begin
if ACol=1 then S:=' 主 场 ';
if ACol=2 then S:='比分';
if ACol=3 then S:=' 客 场 ';
end;
if not isEditCell(Acol,ARow) then begin
if (ACol in [0,2]) then
drawtext(handle,pchar(S),length(S),BARect, DT_CENTER
or DT_SINGLELINE or DT_VCENTER);
if (ARow=0) and (ACol>3) then begin //draw title text
tmpR:=BARect;
inflateRect(editRect,-1,0);
inflateRect(tmpR,-2,0);
S:=inttoStr(Acol-3)+'. '+S;
if (hasSgcols(ACol) or (ColWidths[ACol] in [SGCOLW,epSGCOLW])) and
(TextWidth(S)>editRect.Right-editRect.Left-2-
(btnRect.Right-btnRect.Left) div 2) then
drawtext(handle,pchar(S),length(S),editRect, DT_CENTER
or DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS)
else if Colwidths[ACol] in [epCMPCOLW,SGCOLW,epSGCOLW] then
drawtext(handle,pchar(S),length(S),tmpR, DT_CENTER
or DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS)
end;
if (ACol in [1,3]) then RLalignDraw(BARect,FBufferBmp.Canvas,s); //draw team name;
end;
if (ACol>3) and (ARow=14) then begin
S:='';
if calHitCount(ACol)<>'0' then S:='中 '+calHitCount(ACol)+' 场';
if ColWidths[ACol]=epCMPCOLW then
S:=getAntesCount(ACol)+' 注 '+S
else
S:='单注 '+S ;
drawtext(handle,pchar(S),length(S),BARect, DT_CENTER
or DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS);
end;
if ACol in [0,2] then begin //draw the separely
pen.Width:=1;
pen.Color:=clGray;
moveto(BARect.Right-1,BARect.Top);
lineto(BARect.Right-1,BARect.Bottom);
end;
if (ACol>3) or (ACol=2) then begin //draw the separely
pen.Width:=1;
pen.Color:=clGray;
moveto(BARect.Left,BARect.Top);
lineto(BARect.Left,BARect.Bottom);
end;
if ARow=14 then begin //draw the separely
pen.Width:=1;
pen.Color:=clGray;
moveto(BARect.Left,BARect.Top);
lineto(BARect.Right,BARect.Top);
if ACol=col then begin
pen.Color:=clLime;
moveto(BARect.Left+1,BARect.Bottom-1);
lineto(BARect.Right,BARect.Bottom-1);
pen.Color:=getAlphaColor(clWhite,clLime,96);
moveto(BARect.Left+2,BARect.Bottom-2);
lineto(BARect.Right,BARect.Bottom-2);
end;
end;
if (ACol>3) and (ACol=Col) then begin
pen.Width:=1;
pen.Color:=clLime;
moveto(BARect.Left+1,BARect.Top);
lineto(BARect.Left+1,BARect.Bottom);
moveto(BARect.Right-1,BARect.Top);
lineto(BARect.Right-1,BARect.Bottom);
pen.Color:=getAlphaColor(clWhite,clLime,96);
moveto(BARect.Left+2,BARect.Top);
lineto(BARect.Left+2,BARect.Bottom);
moveto(BARect.Right-2,BARect.Top);
lineto(BARect.Right-2,BARect.Bottom);
end;
if ARow=0 then begin //draw the separely
pen.Width:=1;
pen.Color:=clGray;
moveto(BARect.Left,BARect.Bottom-1);
lineto(BARect.Right,BARect.Bottom-1);
end;
end;
canvas.CopyRect(ARect,FBufferBmp.Canvas,BARect);
end;