Solved

Transparent CustomControl

Posted on 1998-10-29
8
405 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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