Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Clickable Overlay Panel - great for Touch screens
Sat, Apr 17 2021 4:57 PMPermanent Link

Trinione

A technique I use to improve the clickability of areas is to place a transparent panel over it and set the event via the panel.

I have included Click and DblClick handing.

function ClickableOverlayPanel(Sender: TObject; evntType: string; evnt: TNotifyEvent): TBasicPanel;
function CreateClickableOverlayPanel(ctrl: TControl; evnt: TNotifyEvent): TBasicPanel;

function ClickableOverlayPanel(Sender: TObject; evntType: string; evnt: TNotifyEvent): TBasicPanel;
var
 pnl: TBasicPanel;

begin
 pnl := TBasicPanel.Create(nil);
 pnl := CreateClickableOverlayPanel(TControl(Sender), evnt);

 if evntType = 'click' then pnl.OnClick := evnt;
 if evntType = 'dblClick' then pnl.OnDblClick := evnt;

 result := pnl;
end;

function CreateClickableOverlayPanel(ctrl: TControl; evnt: TNotifyEvent): TBasicPanel;
var
 pnlOverlay: TBasicPanel;

begin                                       
 pnlOverlay := TBasicPanel.Create(ctrl);

 pnlOverlay.Height := ctrl.Height;
 pnlOverlay.Width := ctrl.Width;

 pnlOverlay.Borders.Bottom.Visible := False;
 pnlOverlay.Borders.Left.Visible := False;
 pnlOverlay.Borders.Top.Visible := False;
 pnlOverlay.Borders.Right.Visible := False;

 with pnlOverlay do
 begin          
   Top := 0;    
   Left := 0;
   Background.Fill.Color := clTransparent;
 end;

 if evnt <> nil then
   pnlOverlay.Cursor := crPointer;

 result := pnlOverlay;
end;

........................................................
PascalNetwork.com
pascal - the language we love
Sat, Apr 17 2021 5:01 PMPermanent Link

Trinione

An example call would be:

ClickableOverlayPanel(imgLogo, 'click', imgLogoClick);


procedure TForm1.imgLogoClick(Sender: TObject);
begin                                                      
 ShowMessage('imgLogo transparent Overlay Panel clicked! Smile;
end;

........................................................
PascalNetwork.com
pascal - the language we love
Image