- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3101:Making Accelerators Work with a TPageControl

KEYWORDS: Accelerators TPageControl AREA: VCL Programming

The TPageControl found on the Win95 page of the Component
Palette does not currently work with accelerators. However,
it is possible to create a descendant of TPageControl which
includes this feature.

The component shown in the code to follow is such a control.
This TPageControl descendant captures the CM_DIALOGCHAR message.
This allows you to capture key strokes that may be accelerators
for a given form. The CMDialogChar message handler uses the
IsAccel function to determine if the captured key code refers
to an accelerator on one of the TPageControls pages. If so,
the appropriate page is made active and is given focus.

unit tapage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type

  TAPageControl = class(TPageControl)
  private
    procedure CMDialogChar(var Msg: TCMDialogChar); message
     CM_DIALOGCHAR;
  end;

procedure Register;

implementation

procedure TAPageControl.CMDialogChar(var Msg: TCMDialogChar);
var
  i: Integer;
  S: String;
begin
  if Enabled then
    for I := 0 to PageCount - 1 do
      if IsAccel(Msg.CharCode, Pages[i].Caption) and
        Pages[I].TabVisible then begin
        Msg.Result := 1;
        ActivePage := Pages[I];
        Change;
        Exit; // exit for loop.
      end;
  inherited;
end;

procedure Register;
begin
  RegisterComponents('Test', [TAPageControl]);
end;

end.

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile