// Ein Striggrid wird mit einem Bild hinterlegt.


// Getestet mit D4 unter XP

var 
  hig: TBitmap; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
  bm: TBitmap; 
  hb: HBrush; 
begin 
  hig := TBitmap.Create; 
  hig.loadfromfile('c:\texture.bmp'); 
  if (hig.width < StringGrid1.width) 
    or (hig.height < StringGrid1.height) then begin 
    bm := TBitmap.Create; 
    bm.assign(hig); 
    hig.width := StringGrid1.width; 
    hig.height := StringGrid1.height; 
    hb := CreatePatternBrush(bm.handle); 
    SelectObject(hig.canvas.handle, hb); 
    PatBlt(hig.canvas.handle, 0, 0, hig.width, hig.height, PATCOPY); 
    deleteobject(hb); 
    bm.free; 
  end; 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  hig.free; 
end; 
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; 
  Rect: TRect; State: TGridDrawState); 
begin 
  with TStringGrid(sender) do 
    with canvas do begin 
      if (aRow >= FixedRows) and (aCol >= FixedCols) 
        then begin 
        Font.Color := clWhite; // z.B. 
        Brush.Style := bsClear; 
        copyrect(Rect, hig.canvas, Rect); 
        inflateRect(Rect, -2, -2); 
        Drawtext(handle, Pchar(Cells[aCol, aRow]), -1, Rect, 0); 
      end; 
    end; 
end; 
 
procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject); 
begin 
  with TStringGrid(sender) do begin 
    EditorMode := false; 
    Refresh; 
  end; 
end;



 

Zugriffe seit 6.9.2001 auf Delphi-Ecke