0

In a Delphi 10.4.2 win-32 VCL Application in Windows 10, I use this form code to make the form partially transparent:

object Form1: TForm1
  Left = 0
  Top = 0
  BorderStyle = bsNone
  Caption = 'Form1'
  ClientHeight = 378
  ClientWidth = 589
  Color = clRed
  TransparentColor = True
  TransparentColorValue = clGreen
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  Position = poDefault
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    AlignWithMargins = True
    Left = 3
    Top = 3
    Width = 583
    Height = 372
    Align = alClient
    BevelOuter = bvNone
    Color = clGreen
    ParentBackground = False
    TabOrder = 0
    ExplicitLeft = 0
    ExplicitTop = 0
    ExplicitWidth = 589
    ExplicitHeight = 378
  end
end

This has the effect of displaying a red frame with a transparent area inside the frame:

enter image description here

Unfortunately, the transparent area also has a CLICK-THROUGH "feature," which I do not want: The transparent area should only be transparent and clickable and NOT Click-Through, so when I click on the transparent area, I should get a click-event from the Panel.

So how can I deactivate the Click-through feature of the transparent area?

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • If there is an event handler, OnClickThrough, then set it to nil in your code. I don't want to make this an answer as I don't know which event is triggered when you click on the transparent area – No'am Newman Jul 24 '21 at 11:24
  • There is a basic misunderstanding here: I don't want to make the whole form transparent (as I wrote in the question) - only the area of the panel. But `AlphaBlend` makes the WHOLE form transparent, which I do not want. And the only way to get this partial transparency seems to be using the `TForm.TransparentColor` property. But that causes the click-through as I wrote. – user1580348 Jul 24 '21 at 11:40
  • Please don't be sorry. When you try out the form code, then you'll understand better how it works. Panel1 uses `AlignWithMargins` where margins are set to the default value of 3. This creates the red-frame effect. – user1580348 Jul 24 '21 at 12:03
  • You can use the [WS_EX_NOREDIRECTIONBITMAP](https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles) extended window style to create a window whose interior appears transparent, but will not let mouse clicks pass through. Kenny Kerr's MSDN article titled [Windows with C++ : High-Performance Window Layering Using the Windows Composition Engine](https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/june/windows-with-c-high-performance-window-layering-using-the-windows-composition-engine) explains what this window style is for, and how it works. – IInspectable Jul 24 '21 at 12:40
  • Also, see this [Q&A](https://stackoverflow.com/q/49380566/1889329). – IInspectable Jul 24 '21 at 12:41
  • @IInspectable I have not found the declaration of `WS_EX_NOREDIRECTIONBITMAP`, so I replaced it with `$00200000`. Is that correct? – user1580348 Jul 24 '21 at 17:15
  • However, `WS_EX_NOREDIRECTIONBITMAP` makes the whole form transparent. But I want only the area of Panel1 to be transparent! – user1580348 Jul 24 '21 at 17:18
  • The flag was introduced in Windows 8. It's value is 0x00200000. If it isn't available, make sure you set the minimum supported OS and use a properly maintained SDK. I'm not familiar with Delphi, so I cannot help you with that. – IInspectable Jul 24 '21 at 17:20
  • The flag affects the *client* area. Again, I'm not familiar with Delphi nor its windowing component library to know what a *"Form"* boils down to in terms of the OS' windowing system. – IInspectable Jul 24 '21 at 17:22
  • The flag `$00200000` (hex number) does work as intended. – user1580348 Jul 24 '21 at 17:35
  • In Delphi you can set a window as `BorderStyle = Single` with no border icons, which draws a single-line dark gray border around the window. Is it possible to make that border-line RED? – user1580348 Jul 24 '21 at 17:44
  • A strange side-effect: When using `WS_EX_NOREDIRECTIONBITMAP`, then no app icon is shown in the taskbar. But the main problem is that it makes the WHOLE window transparent (which in my case is the client area since I use no borders for this window). – user1580348 Jul 24 '21 at 17:57

0 Answers0