Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (12)


Transparent GridFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Graphic
Skill Level:
Scoring:
Last Update:
02/26/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet grid transparent panel API
Times Scored:
11
Visits:
10354
Uploader: Khaled Shagrouni
Company:
Reference: N/A
 
Question/Problem/Abstract:
How to make a grid or panel transparent?
Answer:



Transparent Grid


This is a quick experiment of how to make a grid transparent and showing any
underline image, the example below is a full unit code, the controls layout of
the form is as the following:


- ADOTable1: (you can use a normal Ttable) showing what ever you want, and
let it be Active.


- DataSource1: Connected to the table above.


- Image1: Aligned to alClient to cover the entire form, with a Bitmap picture
(bmp. Not jpg).


- Panel1: Large enough to host our grid.


- DbGrid1: As a child inside Panel1, make it aligned to alBottom, leave some
space for the upper part of the panel to be visible. Don't forget to link it to
DataSource1.


The code bellow has two procedure, the first is to handle the event
OnDrawDataCell of the DBGrid, which also contain the real work to make the grid
transparent.


The second procedure handle the OnMouseDown event of Panel1, this will move
the Panel and make it transparent also to the image beneath.


 


fTransparentGrid Example:

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


Khaled Shagrouni.







Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Printing from right to left
    saeed (Jul 13 2004 10:40PM)

How it is possible to change bidimode for printer
and set it to bdrighttoleft...
Respond

the problem
    Miguel Ayuso (Feb 20 2003 5:41PM)

the problem
===========

zone of grid that not this stuffed with line is not transparent
Respond

Trasparent grid
    Miguel Ayuso (Feb 19 2003 7:32PM)

As it is possible to be caused that all dbgrid is transparent and non single the rows that estan stuffed

Español
======
Como se puede hacer que todo el dbgrid sea transparente y no solo las filas que estan rellenas
Respond

Transparent grid
    Peter Lawson (Jul 25 2001 10:34PM)

It's just what I need - but what unit is BitBit in? I have Delphi Professional 5
Respond

RE: Transparent grid
Khaled Shagrouni (Jul 26 2001 4:19AM)

Windows.BitBlt ............. (BITBLT)
Respond

RE: RE: Transparent grid
Peter Lawson (Jul 26 2001 8:09PM)

Sorry - silly me :>)
Respond

invalid typecast
    pintiawan cahyadi,ir (Jun 24 2001 9:24AM)

DrawtextEx(DBGrid1.Canvas.Handle,
             PChar(Text),
             Length(Text),
             Rct,
             DT_WORDBREAK,
             nil);

PChar(Text) generates error message : invalid typecast
and it is OK when I change it into PChar(Text+'#0')


Respond

BiDi Mode...
    Abdulaziz Jasser (Jun 9 2001 4:47AM)

Alsalam Alykem…

A very nice article.  But when I switched the “BiDi Mode” of the form and the grid to “bdRightToLeft” (Arab Language need), the data did not appear!!!  Can you fix that?

Thanks…

Respond

RE: BiDi Mode...
Khaled Shagrouni (Jun 9 2001 9:39PM)

Salam, I will try to check it out. Thank you.
Respond

RE: BiDi Mode...
Khaled Shagrouni (Jun 14 2001 8:07PM)

Try one of Canvas print methos like TextRect instead of API DrawText.

Respond

It doesnt work at all
Aref Karimi (Mar 31 2002 10:23AM)

Hi ,
I used this tip but it is not functionint at all. Delphi help recommends not to use OnDrawDataCell 'coz its for backward compatibility and I must use OnDrawColumnCell instead. With ondrawcolumncell event the grid looks so messy !
I have D5.
thanks
Respond

Printing in BiDi mode
Nave H. Weiss (Dec 14 2004 10:30PM)

This way:
printer.Canvas.TextFlags := ETO_RTLREADING;

I realize it's too late (like in 2 years), but this is for the others who encounter the problem. ;)

[ additional keywords since I'm so nice: hebrew printing delphi ]
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)