Advertisement

03.21.2008 at 07:36PM PDT, ID: 23261010
[x]
Attachment Details

Transparent Form Click Through with PNG

Asked by bryan7 in Delphi Programming

I'm trying to do this:

- Load a PNG image that contains alpha channel
- Assign it to a TImage
- Set the form transparent
- Be able to move the form with the mouse over the image
- Be able to click throgh the transparent areas

I used to do this by using a bitmap and setting up regions, and now I've moved on to using Layered window styles for this.

I have accomplished this by using pngimage. This works if I use WHITE as the form's color and the transparent color, but using any other color fails. It still makes the form transparent, but if you click on a transparent area the click doesn't go through and the form takes the click instead.

I guess the problem lies in the timage setting the transparent areas as white when it gets the png object assigned, but even so, the transparency works with any color.

This is the code. I have included a rar with the project, pngimage files that are needed and a test PNG image. Please rename the file to RAR (can't upload .rar to EE)

unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, pngimage, ExtCtrls, StdCtrls;

type
  TForm4 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Button2: TButton;
    Button3: TButton;
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.Button1Click(Sender: TObject);
var p: TPNGObject;
begin
 p:= TPNGObject.Create;
 p.LoadFromFile(ExtractFilePath(Application.ExeName)+'Image6.png');
 Image1.Picture.Assign(p);
 p.Free;
 BorderStyle:= bsNone;

 // if we pick white instead ($ffffff) it works
// Color:= clRed;
// TransparentColorValue:= clRed;

 TransparentColor:= True;
 button1.Enabled:= False;
end;

procedure TForm4.Button3Click(Sender: TObject);
begin
 Close;
end;

procedure TForm4.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if ssleft in shift then
 begin
  releasecapture;
  Form4.perform(WM_syscommand, $F012, 0);
 end;
end;

end.














object Form4: TForm4
  Left = 0
  Top = 0
  Caption = 'Form4'
  ClientHeight = 305
  ClientWidth = 393
  Color = clBtnFace
  TransparentColorValue = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 0
    Top = 0
    Width = 393
    Height = 305
    OnMouseMove = Image1MouseMove
  end
  object Button1: TButton
    Left = 8
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Load PNG'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 208
    Top = 160
    Width = 145
    Height = 49
    Caption = 'This must be clickable too'
    TabOrder = 1
  end
  object Button3: TButton
    Left = 8
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Close'
    TabOrder = 2
    OnClick = Button3Click
  end
endStart Free Trial
Attachments:
 
project files
 
 
Loading Advertisement...
 
[+][-]03.21.2008 at 07:38PM PDT, ID: 21184543

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.22.2008 at 01:50AM PDT, ID: 21185348

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.22.2008 at 04:22AM PDT, ID: 21185602

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.24.2008 at 11:52AM PDT, ID: 21195804

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 05:56AM PDT, ID: 21211057

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 06:19AM PDT, ID: 21211256

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.31.2008 at 05:57AM PDT, ID: 21244887

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.02.2008 at 02:15AM PDT, ID: 21261245

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 05:59AM PDT, ID: 21272067

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Delphi Programming
Sign Up Now!
Solution Provided By: bryan7
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906