• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

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
0
hatecapletters
Asked:
hatecapletters
  • 5
  • 5
  • 4
1 Solution
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now