Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Use of hot keys

edited August 2005 in General
Is it possible to use hot-keys in prewiev mode.

In our application if user desire print out to the printer he must use
mouse to click the "Print" button. Is it possible to activate printing
using some hot keys like Ctrl + P?

Martin.

Comments

  • edited August 2005
    Hi Martin,

    You will need to create a custom preview plugin that exposes the OnKeyDown
    event in order to accomplish this. Below is a snip of code and an article
    on creating a preview plugin..

    -----------------------------------------
    Article: Creating a Preview Plugin
    -----------------------------------------

    Q: I've followed the tutorials and registered a Preview Form replacement but
    that did not affect the TppDesigner's Preview workspace.


    A: Do not use the form replacement, but rather, there is a different
    architecture built into the preview form that is registered by default.



    You will need to register a TppPreview descendent. The class you register
    is used to create the preview controls inside the standard print preview
    form and the designer preview workspace.


    Here is an example of creating a simple custom preview that access the
    viewer its been assigned in order to change the page color. You can also do
    more advanced operations such as adding and removing buttons and change the
    behavior of the preview form. Access the inherited controls via. protected
    properties and override the virtual methods in order to customize behavior.

    Open ppPreview.pas and view the TppPreview class as a guide to create a
    custom preview descendent.


    unit MyPreviewPlugin;

    interface

    uses
    ppPreview;

    type
    TMyPreviewPlugin = class(TppPreview)
    public
    procedure BeforePreview; override;

    end;


    implementation

    uses
    Graphics;


    procedure TMyPreviewPlugin.BeforePreview;
    begin
    inherited BeforePreview;

    Viewer.PageColor := clRed;

    end;

    initialization
    TppPreviewPlugIn.Register(TMyPreviewPlugin);

    finalization
    TppPreviewPlugIn.UnRegister(TMyPreviewPlugin);

    end.


    ---------
    HotKey example....


    unit HotKeyPrintPlugin;

    interface

    uses
    Classes, Windows,
    ppPreview;

    type

    TmyHotKeyPrint = class(TppPreview)
    public
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;

    end;

    implementation

    { TmyHotKeyPrint }

    procedure TmyHotKeyPrint.KeyDown(var Key: Word; Shift: TShiftState);
    begin

    inherited KeyDown(Key, Shift);

    if (Shift = []) and (Key = VK_F8) then
    Print;

    end;

    initialization
    TppPreviewPlugIn.Register(TmyHotKeyPrint);

    finalization
    TppPreviewPlugIn.UnRegister(TmyHotKeyPrint);


    end.


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.