如何在StringGrid控件中每格显示两行,且可以分别设置两行的颜色

来源:互联网 发布:mac怎么调输入法 编辑:程序博客网 时间:2024/05/03 02:24
procedure TForm1.Grid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  Rect1:TRect;
  Rect2:TRect;
begin
  Rect1.Left:=ACol*(Rect.Right-Rect.Left)+2;
  Rect1.Top:=ARow*(Rect.Bottom-Rect.Top)+2;
  Rect1.Right:=Rect1.Left+(Rect.Right-Rect.Left)-2;
  Rect1.Bottom:=Rect1.Top+(Rect.Bottom-Rect.Top) div 2+2;
  //-----
  Rect2.Left:=ACol*(Rect.Right-Rect.Left)+2;
  Rect2.Top:=ARow*(Rect.Bottom-Rect.Top)+(Rect.Bottom-Rect.Top)div 2+2;
  Rect1.Right:=Rect1.Left+(Rect.Right-Rect.Left)-2;
  Rect1.Bottom:=Rect1.Top+(Rect.Bottom-Rect.Top)+2;

  if gdSelected  in state then
     begin
       Grid1.Canvas.Brush.Color:=clWhite;
       Grid1.Canvas.TextRect(Rect1,Rect1.Left,Rect1.Top,'xxxx');
       Grid1.Canvas.Brush.Color:=clWhite;
       Grid1.Canvas.TextRect(Rect2,Rect2.Left,Rect2.Top,'yyyy');
     end else
     begin
       Grid1.Canvas.Brush.Color:=clInfoBk;
       Grid1.Canvas.TextRect(Rect1,Rect1.Left,Rect1.Top,'xxxx');
       Grid1.Canvas.Brush.Color:=clLime;
       Grid1.Canvas.TextRect(Rect2,Rect2.Left,Rect2.Top,'yyyy');
     end;

end;
原创粉丝点击