Skip to content

AutoClick Feature Demo

Overview

This demo showcases the AutoClick feature available in all StyledComponents buttons and dialogs. AutoClick allows buttons to automatically trigger their Click event after a specified delay.

AutoClick Demo

What You'll Learn

  • How to enable AutoClick on buttons
  • Setting AutoClickDelay values
  • Using AutoClick with different button styles
  • AutoClick in TStyledTaskDialog
  • Practical use cases for automatic button clicks

AutoClick Buttons

The demo displays three buttons with different styles and AutoClick delays:

Rounded Button

  • StyleDrawType: btRounded
  • Default Delay: 3000ms (3 seconds)
  • Style: Bootstrap Primary

RoundRect Button

  • StyleDrawType: btRoundRect
  • Default Delay: 5000ms (5 seconds)
  • Style: Bootstrap Success

Rectangle Button

  • StyleDrawType: btRect
  • Default Delay: 7000ms (7 seconds)
  • Style: Bootstrap Warning

How It Works

Enabling AutoClick

pascal
AutoClickButton.AutoClick := False;  // First disable
AutoClickButton.AutoClickDelay := 3000;  // Set delay in milliseconds
AutoClickButton.AutoClick := True;  // Then enable

Visual Countdown

When AutoClick is enabled:

  1. Button background color is drawn progressively for each second of AutoClickDelay duration.
  2. Timer counts down to zero
  3. Click event fires automatically
  4. OnClick event handler executes

Manual Override

Users can still click the button manually before the delay expires:

  • Clicking stops the countdown
  • Click event fires immediately
  • AutoClick resets if enabled again

Adjustable Delays

The demo includes spin editors to change delays:

  • Rounded Button Delay: Adjustable from 1-10 seconds
  • RoundRect Button Delay: Adjustable from 1-10 seconds
  • Rectangle Button Delay: Adjustable from 1-10 seconds

Click "Start AutoClick" to apply new delays and restart timers.

AutoClick with Dialogs

The demo includes a special section for testing AutoClick with TStyledTaskDialog:

Dialog AutoClick Options

AutoClick Checkbox

Enable/disable automatic dialog closing.

Delay Spin Editor

Set dialog AutoClick delay (default: 5 seconds).

Toggle between normal buttons and command link style.

Test Dialog Features

The test dialog demonstrates:

  • HyperLinks: Clickable links in message text
  • File Paths: Links to open files
  • Executables: Links to run programs
  • Folders: Links to open directories
  • Websites: Links to visit URLs

Example dialog message:

pascal
LMessage :=
  'The file was created: <A HREF="C:\Windows\System32\license.rtf">license.rtf</A>'+sLineBreak+
  'You can run: <A HREF="C:\Windows\System32\Notepad.exe">Notepad Editor</A>'+sLineBreak+
  'You can open folder: <A HREF="C:\Windows\System32\">C:\Windows\System32\</A>'+sLineBreak+
  'You can visit site: <A HREF="http://www.ethea.it">www.Ethea.it</A>';

AutoClick Dialog Execution

pascal
procedure TfmAutoClick.TestDialogsStyledButtonClick(Sender: TObject);
var
  LAutoClickDelay: Integer;
begin
  if cbAutoClick.Checked then
    LAutoClickDelay := DialogsSpinEdit.Value
  else
    LAutoClickDelay := -1;  // Disable AutoClick

  if cbUseCommandLinks.Checked then
    DoStyledTaskMessageDlg(
      'Dialog Title - use Command Links', LMessage,
      TMsgDlgType.mtConfirmation,
      [mbAbort, mbRetry, mbIgnore], 0, LAutoClickDelay, True)
  else
    DoStyledTaskMessageDlg('Dialog Title - use normal Buttons', LMessage,
      TMsgDlgType.mtWarning,
      [mbOK, mbCancel], 0, LAutoClickDelay, False);
end;

Use Cases

1. Countdown Confirmations

Show a confirmation dialog that auto-confirms after a delay:

pascal
Btn.Caption := 'Confirm';
Btn.AutoClickDelay := 10000;  // 10 seconds
Btn.AutoClick := True;
// User has 10 seconds to cancel

2. Auto-Closing Notifications

Information dialogs that close automatically:

pascal
StyledTaskDialog.AutoClickDelay := 5000;  // 5 seconds
StyledTaskDialog.AutoClick := True;
StyledTaskDialog.Execute;

3. Demo/Tutorial Modes

Automated demonstrations:

pascal
// Click through demo steps automatically
NextButton.AutoClickDelay := 3000;
NextButton.AutoClick := True;

4. Timed Operations

Operations with automatic timeout:

pascal
CancelButton.Caption := 'Cancel (30)';
CancelButton.AutoClickDelay := 30000;  // 30 seconds
CancelButton.AutoClick := True;

Technical Details

AutoClick Properties

PropertyTypeDescription
AutoClickBooleanEnable/disable automatic clicking
AutoClickDelayIntegerDelay in milliseconds before click

Supported Components

AutoClick is available on:

  • TStyledButton
  • TStyledGraphicButton
  • TStyledBitBtn
  • TStyledSpeedButton
  • TStyledToolButton (in toolbars)
  • TStyledTaskDialog

Important Notes

  1. Disable Before Changing: Always set AutoClick := False before changing delay
  2. Re-enable After: Set AutoClick := True to restart countdown
  3. OnClick Fires: The OnClick event fires normally when AutoClick triggers
  4. Manual Override: User can click before delay expires
  5. Visual Feedback: Caption updates with countdown (configurable)

Source Code Example

pascal
procedure TfmAutoClick.StartAutoClick;
begin
  // Rounded button - 3 seconds
  AutoClickButtonRounded.AutoClick := False;
  AutoClickButtonRounded.AutoClickDelay := RoundedSpinEdit.Value;
  AutoClickButtonRounded.AutoClick := True;

  // RoundRect button - 5 seconds
  AutoClickButtonRoundRect.AutoClick := False;
  AutoClickButtonRoundRect.AutoClickDelay := RoundRectSpinEdit.Value;
  AutoClickButtonRoundRect.AutoClick := True;

  // Rect button - 7 seconds
  AutoClickButtonRect.AutoClick := False;
  AutoClickButtonRect.AutoClickDelay := RectSpinEdit.Value;
  AutoClickButtonRect.AutoClick := True;
end;

procedure TfmAutoClick.AutoClick(Sender: TObject);
var
  LCaption: string;
begin
  LCaption := (Sender as TStyledButton).Caption;
  StyledShowMessageFmt('"%s" - Clicked!', [LCaption]);
end;

Technical Details

Source Location

Demos/source/AutoClickForm.pas

Supported Versions

All Delphi versions (XE6+)

Initialization

pascal
procedure TfmAutoClick.FormCreate(Sender: TObject);
begin
  //Initialize Task Dialogs Defaults using Bootstrap buttons:
  InitializeStyledTaskDialogs('Bootstrap');
end;

See Also

Released under Apache License, Version 2.0.