Solved

Transparent CustomControl

Posted on 1998-10-29
8
395 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
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.

 
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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

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

27 Experts available now in Live!

Get 1:1 Help Now