Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi TStringGrid transparent (https://www.delphipraxis.net/137771-tstringgrid-transparent.html)

Spanky 28. Jul 2009 14:10


TStringGrid transparent
 
Hallo,

ich möchte gerne ein TStringGrid transparent zeichnen. Ich habe schon Folgendes ausprobiert:

Delphi-Quellcode:
procedure TfrmMain.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  celltext: String;
begin
  SetBkMode(StringGrid1.Canvas.Handle, TRANSPARENT);
  StringGrid1.Canvas.Brush.Style := bsClear;
  StringGrid1.Canvas.Pen.Style := psClear;
  StringGrid1.Canvas.FillRect(Rect);
  StringGrid1.Canvas.Font.Color := clBlack;
  celltext := StringGrid1.Cells[ACol, ARow];
  DrawText(StringGrid1.Canvas.Handle, PChar(celltext), Length(celltext), Rect, DT_SINGLELINE);
end;
Das klappt aber nicht. Das Rechteck bleibt weiß.

Wo liegt der Fehler?

Lannes 28. Jul 2009 21:58

Re: TStringGrid transparent
 
Hallo,

was soll denn als Hintergrund dargestellt werden?

Spanky 29. Jul 2009 08:27

Re: TStringGrid transparent
 
Ein TImage. :wink:

Lannes 29. Jul 2009 11:39

Re: TStringGrid transparent
 
Hallo,

soll das Image nur im Bereich des StringGrids sichtbar sein, oder bedeckt das StringGrid nur einen Teil des Image?

Das onDrawCell wird ja für jede Zelle die gezeichnet werden muss aufgerufen.
Also musst du Anhand der Zellkoordinate(die liefert Dir OnDrawCell in der Prozedurvariablen rRect) den entsprechenden Bereich aus dem Image kopieren und in der Zelle mit Canvas... ausgeben.

In Deinem Code wird an keiner Stelle etwas gezeichnet, also weiße Fläche(Brush.Color) :wink:

Transparent in dem Sinne das das hinterliegende Image "durchscheint" ist imho nicht möglich.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz