Solved

Transparent CustomControl

Posted on 1998-10-29
8
399 Views
Last Modified: 2010-04-06
I have a control descended from TCustomControl.  At certain times I want it to become transparent.  To that end, I have added the following code (overridden)

procedure TcbImageBtn.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle:=Params.ExStyle or WS_EX_TRANSPARENT;
end;

When the component is supposed to be transparent, I do nothing except call inherited in the Paint routine.  When it is not transparent, I do a Canvas.Draw(0,0,Picture).

When the component first appears, it is transparent, and it works.  It then goes to an opaque status, and paints the image OK.  Then when it returns to transparent status, it becomes a black rectangle.

Any ideas anyone?
0
Comment
Question by:bcrotaz
8 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1345000
Did you try Invalidating or Refreshing the Canvas of its parent?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1345001
Is the paint routine being called when it is appearing as a black rectangle?
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1345002
Hello bcrotaz!

What you need to do is use this procedure whenever you want to update your transparency status...

//some code... Status := Trans;
RecreateWnd;
//Rest of code...

Cheers,
Viktor
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:bcrotaz
ID: 1345003
You either (but not both) have to call RecreateWnd or Invalidate.

Thanks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345004
Hello again!

I never said you need to call both.. What I said is just call the RecreateWnd; whenever you need to update the transparency... That's all =)

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1345005
What I've ended up with (which works btw) is to do

procedure ChangeState(NewState: Boolean)
begin
  if CurrentState <> NewState then
    begin
      CurrentState:=NewState;
      if Transparent then
        RecreateWnd
      else
        Invalidate;
    end;

Wouldn't it be loverly ( you could make a song from that...) if the Delphi help included things like this....  Or even just how to change the creation parameters of a window - that took me ages to find.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1345006
That looks ok to me... What kind of states does your control have????

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1345007
It's an image btn, with an up and down image.  if no image is given for a state, then that state is transparent.  The states are stUp and stDown.

Pretty simple really, but dammed useful when you have a large background image with graphical buttons which (eg) light up when the mouse goes down over them.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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