Link to home
Start Free TrialLog in
Avatar of ghjm
ghjm

asked on

Click-through forms

Delphi 6 now provides the ability to create an alpha-blended (i.e. translucent) form. What I would like to do is create a form like this, with FormStyle = fsStayOnTop, as a sort of 'watermark' that always shows as a light overlay in front of whatever's on the screen. The problem, of course, is that with my form in front of whatever else is on the system, mouse clicks go to my form, not to things behind my form. So my question is, how can a Delphi form be made 'transparent' to mouse clicks - i.e. make sure all mouse clicks are routed to the window in the second-topmost position at the pixel that was clicked. Bonus points if you write the code for me. :-)
Avatar of gemarti
gemarti
Flag of United States of America image

This works, but may not be what your looking for. I'm just guessing since D6 is new to me:

Create a new application.
Place a Button and a edit control on the first form (Form1)
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

Create a second form (form2)

Set AlphaBlend := true;
AlphaBlendValue := 100 (or any value from 0..255 where 255 is the least transparent)
Set TransParentColor := true;
Set TransParentColorValue := clBtnFace (or whatever color works for you)

Add these lines of code:
procedure TForm2.FormActivate(Sender: TObject);
begin
  Form1.Button1.Parent := Form2;
  Form1.Edit1.Parent := Form2;
  Form2.AlphaBlendValue := 200; //if you leave at 100 you can't see the components very well.
  Form1.Button1.GetParentComponent;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Form1.Button1.Parent := Form1;
  Form1.Edit1.Parent := Form1;
  Form2.AlphaBlendValue := 100;
end;
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghjm
ghjm

ASKER

Well, I understand what you're trying to do, but I haven't been able to make it work. I'm still trying, but...I sure wish a Win32 API call existed to set the _mouse_ region without also setting the _display_ region.
Avatar of ghjm

ASKER

Okay, well I have it working, sort of. The remaining problem is that whenever a click event goes through, the transparent form disappears and reappears - even though bRedraw is set to FALSE. Any suggestions how to avoid this?