procedure Tfrmdeparttable.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if arow=0 then begin StringGrid1.Canvas.Brush.Color := clinfobk; StringGrid1.Canvas.pen.Color := StringGrid1.Font.Color ; StringGrid1.canvas.fillRect(rect); StringGrid1.Canvas.textout(rect.left+1,rect.Top ,StringGrid1.cells[acol,arow]); end;end;
上面的是改变背景色 左右居中,上下居中再加入代码: if arow=0 then begin if acol=0 then stringgrid1.canvas.textout(rect.left+15,rect.top+5,'姓名'); if acol=1 then stringgrid1.canvas.textout(rect.left+5,rect.top+5,'日(月)薪'); if acol=2 then stringgrid1.canvas.textout(rect.left+5,rect.top+5,'工作天数'); end; 是给一个固定的SELLS中的字符固定位置
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if Acol=0 then
StringGrid1.Canvas.Font.Color := clblack
else
StringGrid1.Canvas.Font.Color := clgreen;
end;可是不行
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if arow=0 then
begin
StringGrid1.Canvas.Brush.Color := clinfobk;
StringGrid1.Canvas.pen.Color := StringGrid1.Font.Color ;
StringGrid1.canvas.fillRect(rect);
StringGrid1.Canvas.textout(rect.left+1,rect.Top ,StringGrid1.cells[acol,arow]);
end;end;
左右居中,上下居中再加入代码:
if arow=0 then
begin
if acol=0 then stringgrid1.canvas.textout(rect.left+15,rect.top+5,'姓名');
if acol=1 then stringgrid1.canvas.textout(rect.left+5,rect.top+5,'日(月)薪');
if acol=2 then stringgrid1.canvas.textout(rect.left+5,rect.top+5,'工作天数');
end;
是给一个固定的SELLS中的字符固定位置