Use panel as a button

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Use panel as a button

Post by Grovkillen » Mon May 22, 2023 1:31 pm

You may want to add some more style to your buttons and you can easily do that by using panel elements as buttons. See example code below:

Code: Select all

Let>BUTTON_COLOR_down=8421631
Let>BUTTON_COLOR_up=15658734

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 156
  ClientWidth = 160
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 48
    Top = 47
    Width = 65
    Height = 66
    BevelWidth = 2
    Caption = 'OK'
    ParentBackground = False
    TabOrder = 0
  end
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,Panel1,Color,BUTTON_COLOR_up
AddDialogHandler>Dialog1,Panel1,OnMouseDown,BUTTON_CLICK_down
AddDialogHandler>Dialog1,Panel1,OnMouseUp,BUTTON_CLICK_up
AddDialogHandler>Dialog1,Panel1,OnClick,BUTTON_CLICK_action

Show>Dialog1,r

SRT>BUTTON_CLICK_down
  SetDialogProperty>Dialog1,Panel1,Color,BUTTON_COLOR_down
  SetDialogProperty>Dialog1,Panel1,BevelKind,bkFlat
  SetDialogProperty>Dialog1,Panel1,BevelOuter,bvNone
END>BUTTON_CLICK_down

SRT>BUTTON_CLICK_up
  SetDialogProperty>Dialog1,Panel1,Color,BUTTON_COLOR_up
  SetDialogProperty>Dialog1,Panel1,BevelKind,bkNone
  SetDialogProperty>Dialog1,Panel1,BevelOuter,bvRaised
END>BUTTON_CLICK_up

SRT>BUTTON_CLICK_action
  Message>button is clicked
END>BUTTON_CLICK_action
Using this approach, you can without much effort add more elements on this panel element (images, more text, even progressbars etc.).
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts