Solved

TDbCtrlGrid: how to draw a transparent image?

Posted on 2008-10-20
4
1,874 Views
Last Modified: 2013-11-23
Hi,
I've a TDBGrid-component and want to draw images on it depending from an integer-value in the database. It'works well, but I can't make the images transparent. There are simple images, I put the images-background to color clBtnFace and draw i.e a green rectangle. On the CtrlGrid the background of the image is always white. I tried to set the "TransparentColor" but without success. The images are 24Bit. Her's my code:

procedure TForm1.DBCtrlGrid1PaintPanel(DBCtrlGrid: TDBCtrlGrid;
  Index: Integer);
var
  bitmap : TBitmap;
  fixRect : TRect;
  vTyp : integer;
begin
    vTyp :=  DBCtrlGrid.DataSource.DataSet.FieldByName('Typ').AsInteger;
    if vTyp < ImageList1.Count then
    begin
      bitmap := TBitmap.Create;
      try
        ImageList1.GetBitmap(vTyp,bitmap);
        fixRect.Top := 0;
        fixRect.Bottom := fixRect.Top+32;
        fixRect.Left := E_Typ.Left+ E_Typ.Width + 3;
        fixRect.Right := fixRect.Left+32;
        DBCtrlGrid.Canvas.StretchDraw(fixRect,bitmap);
      finally
        FreeAndNil(bitmap);  
      end;
    end;
end;

Thanks for your help, Peter
0
Comment
Question by:formi
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 250 total points
ID: 22783546
Hi, add the following line before you draw the image. I've attached the resultant snippet also.

DBCtrlGrid.Canvas.CopyMode := cmMergeCopy;

Atul
procedure TForm1.DBCtrlGrid1PaintPanel(DBCtrlGrid: TDBCtrlGrid;

  Index: Integer);

var

  bitmap : TBitmap;

  fixRect : TRect;

  vTyp : integer;

begin

    vTyp :=  DBCtrlGrid.DataSource.DataSet.FieldByName('Typ').AsInteger;

    if vTyp < ImageList1.Count then

    begin

      bitmap := TBitmap.Create;

      try

        ImageList1.GetBitmap(vTyp,bitmap);

        fixRect.Top := 0;

        fixRect.Bottom := fixRect.Top+32;

        fixRect.Left := E_Typ.Left+ E_Typ.Width + 3;

        fixRect.Right := fixRect.Left+32;

        DBCtrlGrid.Canvas.CopyMode := cmMergeCopy;

        DBCtrlGrid.Canvas.StretchDraw(fixRect,bitmap);

      finally

        FreeAndNil(bitmap);  

      end;

    end;

end;

Open in new window

0
 

Author Comment

by:formi
ID: 22783677
Great, it works. Thank a lot!
0
 

Author Closing Comment

by:formi
ID: 31507785
Yes, it works! Great and thanks a lot! (I'm new in experts-exchange and so I didn't saw the button to accept the solution and to send comments to you, so I added a small comment). Peter
0
 
LVL 16

Expert Comment

by:CodedK
ID: 22784020
Hi formi,

Give it a show with icons.
TICon.Create  etc...

Alternative solution is to use TMS components.
http://www.tmssoftware.com/site/gridpack.asp
They have very good components (but expensive).

Another solution is to try with Bergsoft
http://www.bergsoft.net/
Overview : http://www.bergsoft.net/component/next-dbgrid/overview.htm
you can download a demo to see for yourself...

Hope this helps :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
word0 challenge 4 66
wordcount challenge 11 110
Delphi 2 51
Error E2158 compiling with Delphi XE10 Seattle 2 88
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now