Thema: Delphi DBgrid transparent

Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: DBgrid transparent

  Alt 6. Sep 2018, 18:58
*ungetestet* von hier.
Delphi-Quellcode:
unit fTransparentGrid;

interface

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

type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
Image1: TImage;
Panel1: TPanel;
DBGrid1: TDBGrid;
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
Text: string;
Rct: TRect;
begin
Text := Field.AsString;
Rct:= Rect;

BitBlt(DBGrid1.Canvas.handle,
Rct.left,
Rct.top,
Rct.right - Rct.left,
Rct.bottom - Rct.top,
Image1.Canvas.Handle,
Rct.left + DBGrid1.Left + Panel1.Left,
Rct.Top + DBGrid1.Top + Panel1.Top,
SRCCOPY);

SetBkModE(DBGrid1.Canvas.Handle, TRANSPARENT);
DBGrid1.Canvas.Font.Style := [fsBold];
DrawtextEx(DBGrid1.Canvas.Handle,
PChar(Text),
Length(Text),
Rct,
DT_WORDBREAK,
nil);

end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Panel1.Perform(WM_SYSCOMMAND, $F012, SC_MOVE);
Application.ProcessMessages ;

BitBlt(GetDc(Panel1.Handle),
0,
0,
Panel1.Width,
Panel1.Height,
Image1.Canvas.Handle ,
Panel1.Left, Panel1.Top,
SRCAND);

DBGrid1.refresh;
end;


end.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat