Link to home
Start Free TrialLog in
Avatar of hatecapletters
hatecapletters

asked on

watermark on stringgrid

I need to know how to place an image (preferably transparent) on a stringgrid. It should be overwritten with any row-col lines, and the content of the cells
Avatar of rwilson032697
rwilson032697

You could do something like this (assuming you have a TImage called BackgroundImage big enough to fit over the string grid):

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState);

begin
  with Sender as TStringGrid do
  begin
    Canvas.CopyRect(Rect, BackgroundImage.Canvas, Rect);
    canvas.textout(rect.x+2, rect.y+2, cells[col, row]);
    if gdFocused in State then
      Canvas.DrawFocusRect(Rect);
  end;
end;

Cheers,

Raymond.
Avatar of Eddie Shipman
This will place the graphic in EACH CELL.
In order to fill the entire grid with an image, you will need to "chop up" the image.

I have some code at home that does this an will post it tomorrow.


Hi Ed, take a closer look at the code, c'mon don't be shy now :-)

Cheers,

Raymond.
Avatar of hatecapletters

ASKER

sorry for the delay, but I've been busy with other things.. I've tried just about everything with your suggstions, but I haven't been able to get it right so far..
What happens that is not right?
i don't get the image ti show.. maybe its because its not as big as the entire stringgrid ?
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, that works :-) (only with bmp's but what the heck). now there's just one problem: it overwrites the fixed rows, is there a way around that ?
Yes, change it to this:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
 with Sender as TStringGrid do
  begin
    if not State in gdFixed then
     begin
       Canvas.CopyRect(Rect, BackgroundImage.Canvas, Rect);
       Canvas.textout(rect.left+2, rect.top+2, cells[ACol, ARow]);
       if gdFocused in State then
         Canvas.DrawFocusRect(Rect);
     end;
  end;
end;
EddieShipman changed the proposed answer to a comment
OOPS, should read:
if not (gdFixed in State)
that works :-)

thank you to Eddie too. If I had more points on my account, I would have offered some to you too.
Hey no problem, I couldn't find the source that I mentioned earlier in the thread.

Be aware, however, that the effect is not very appealing...

Good Luck...
actually I'm quite happy with the effect, after I put canvas.brush.style := bsclear; right before canvas.textout...  :-)