首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

想把StringGrid控件中某一个格画上两种颜色,上面1/4为绿色,下面的为红色,请教代码该如何写

2012-03-07 
想把StringGrid控件中某一个格画上两种颜色,上面1/4为绿色,下面的为红色,请问代码该怎么写?rt[解决办法]//

想把StringGrid控件中某一个格画上两种颜色,上面1/4为绿色,下面的为红色,请问代码该怎么写?
rt

[解决办法]
//在OnDrawCell事件中写
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
TopRect, BottomRect: TRect;
begin
if (ARow = 1) and (ACol = 2) then //在第1行第2列中画
begin
TopRect := Rect;
TopRect.Bottom := (TopRect.Top + (Rect.Bottom - Rect.Top) div 4);
SubtractRect(BottomRect, Rect, TopRect);

with StringGrid1.Canvas do
begin
Brush.Color := clGreen;
FillRect(TopRect);
Brush.Color := clRed;
FillRect(BottomRect);
end;
end;
end;

热点排行