Recent

Author Topic: TStringGrid skinning problem : Image above text  (Read 3611 times)

lainz

  • Guest
TStringGrid skinning problem : Image above text
« on: October 11, 2010, 06:10:32 pm »
I need the image is below the text, but always remains above: How i can fix it? (see the attach selectgrid.png).

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
  DBGrids;

type

  { TForm1 }

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
      aRect: TRect; aState: TGridDrawState);
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  Bitmap1: TBitmap;
  Bitmap2: TBitmap;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  aRect: TRect; aState: TGridDrawState);
begin
  if (aCol = 0) or (aRow = 0) then begin
  StringGrid1.Canvas.StretchDraw(aRect,Bitmap2);
  end;
  if gdSelected in aState then begin
  StringGrid1.Canvas.StretchDraw(aRect,Bitmap1);
  end;
  StringGrid1.Cells[aCol,aRow] := 'Hello';
end;

initialization

Bitmap1 := TBitmap.Create;
Bitmap1.LoadFromFile('gradient.bmp');

Bitmap2 := TBitmap.Create;
Bitmap2.LoadFromFile('gradient2.bmp');

end.

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: TStringGrid skinning problem : Image above text
« Reply #1 on: October 11, 2010, 10:48:55 pm »
write the text above the bitmap (meaning draw it AFTER you draw bitmap):
1: StringGrid1.Canvas.StretchDraw(aRect,Bitmap1);
2: StringGrid1.Canvas.TextRect(aRect, 2, 5, 'Hello');     // or the value of cells property

(that 2 is ok, but i;d recalculate that 5 on app atart)

 

TinyPortal © 2005-2018