Solved

Transparent CustomControl

Posted on 1998-10-29
8
393 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
 
LVL 1

Author Comment

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

Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

21 Experts available now in Live!

Get 1:1 Help Now