Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Execute a Custom Action on the Form's Help button Click

By Zarko Gajic, About.com

Custom biHelp Action

If the form's BorderStyle property is bsDialog and biHelp is included in BorderIcons, a question mark appears in the form's title bar and when clicked, the cursor changes to crHelp.

If you want to execute some custom code when the user clicks the Help button, you need to handle two Windows messages: WM_NCLBUTTONUP and WM_NCLBUTTONDOWN. Those messages are posted to the window when the user presses and releases the left mouse button while the cursor is within the non-client area of a window.

Here's a simple implementation of the custom biHelp-click action:

type
   THelpForm = class(TForm)
   private
     procedure WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ; message WM_NCLBUTTONDOWN;
     procedure WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ; message WM_NCLBUTTONUP;
   end;

var
   HelpForm: THelpForm;

implementation
{$R *.dfm}

procedure THelpForm.WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ;
begin
   if Msg.HitTest = HTHELP then
     Msg.Result := 0 // "eat" the message
   else
     inherited;
end;

procedure THelpForm.WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ;
begin
   if Msg.HitTest = HTHELP then
   begin
     Msg.Result := 0;
     ShowMessage('Need help?') ;
   end
   else
     inherited;
end;

Delphi tips navigator:
» How to Draw Custom Text on a Form's Caption Bar
« How to "Pan" an Image inside a ScrollBox

More Delphi Programming Quick Tips

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2006 Tips
  7. Execute a Custom Action on the Form's Help button Click (biHelp in Delphi)

©2009 About.com, a part of The New York Times Company.

All rights reserved.