读书人

想把StringGrid控件中某一个格画上两种

发布时间: 2012-03-07 09:13:51 作者: rapoo

想把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;

读书人网 >.NET

热点推荐