Solved

Timage transparenty on transparent form

Posted on 2006-11-02
4
247 Views
Last Modified: 2010-04-05
Hello developers

I have successfully created a TImage with transparency using this code:

  Image1.Picture.Bitmap.TransparentColor :=  Image1.Picture.Bitmap.Canvas.Pixels[50,300];    
  Image1.Picture.Bitmap.TransparentMode := tmFixed;
  Image1.Transparent := true;

This works fine.

Secondy I need my form to be transparent, which is done using this code:

procedure TForm.FormCreate(Sender: TObject);
var
  hRgn: Cardinal;
  i: Integer;
begin
 //Transparentform
  with FormProducts do
  begin
    BorderStyle := bsNone;
    hRgn := CreateRectRgn(0, 0, 0, 0);
    for i := 0 to ControlCount - 1 do
      with Controls[i].BoundsRect do
        CombineRgn(hRgn, hRgn, CreateRectRgn(Left, Top, Right, Bottom), RGN_OR);
    SetWindowRgn(handle, hRgn, True);
  end;
end;

Which also works. The problems arise when these snippets are combined. The image doesn't show the graphics behind the form, but shows the color the form was before it became transparent. Any idea how to get around this problem?

My main task is to create a form which isn't triangular. I need some of the edges to be round and follow the shape of some images. If anyone has a different idea to do this it would also be most welcome.
0
Comment
Question by:Robert_MP
4 Comments
 
LVL 11

Expert Comment

by:Mihai Stancescu
Comment Utility
Try to put the transparent color of the form to the color that remains visible.

Regards,
Mishu
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 250 total points
Comment Utility
You need to intercept the WM_EraseBkgnd message passed to the form. something like:

type
  TMyTransparentForm = Class(TCustomForm)
...
  private
    procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
...  
  end;

...
procedure TForm1.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
  Message.Result:= 1;
end;
...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

9 Experts available now in Live!

Get 1:1 Help Now