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
hatecaplettersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
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.
0
Eddie ShipmanAll-around developerCommented:
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.


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

Cheers,

Raymond.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

hatecaplettersAuthor Commented:
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..
0
rwilson032697Commented:
What happens that is not right?
0
hatecaplettersAuthor Commented:
i don't get the image ti show.. maybe its because its not as big as the entire stringgrid ?
0
rwilson032697Commented:
I put the code in a unit as below. The form has a Tstriggrid and a TImage component (with an image assigned). It draws the image as a background to the stringgrid...

unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    BackgroundImage: TImage;
    StringGrid1: TStringGrid;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
 with Sender as TStringGrid do
  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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hatecaplettersAuthor Commented:
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 ?
0
Eddie ShipmanAll-around developerCommented:
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;
0
Eddie ShipmanAll-around developerCommented:
EddieShipman changed the proposed answer to a comment
0
Eddie ShipmanAll-around developerCommented:
OOPS, should read:
if not (gdFixed in State)
0
hatecaplettersAuthor Commented:
that works :-)

thank you to Eddie too. If I had more points on my account, I would have offered some to you too.
0
Eddie ShipmanAll-around developerCommented:
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...
0
hatecaplettersAuthor Commented:
actually I'm quite happy with the effect, after I put canvas.brush.style := bsclear; right before canvas.textout...  :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.