Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Transparent CustomControl

Posted on 1998-10-29
8
Medium Priority
?
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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