📄 dosmove.pas
字号:
//-----------------------------------------------------------------------------
// TDosMove ver 1.02
//
// Last updated at: 09/10/1998
//
// Component that allows you to move thourgh the controls in your app with
// UP/DOWN arrows or ENTER key insted of using the old boring TAB.
//
// Code by: Liran Shahar
// Israel
// simpletech@ibm.net
//-----------------------------------------------------------------------------
// Modify Version 1.02c
// Designer : DEVEN
// E-Mail: clipe@mail.apol.com.tw
//
unit DosMove;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TMoveOptions = set of (moEnter,moUpDn);
TDosMove = class(TComponent)
private
FActive : boolean;
FOptions : TMoveOptions;
FEditNoBeep : boolean;
FOwnerKeyDown : TKeyEvent;
FOwnerKeyPress : TKeyPressEvent;
FLastWasEdit : boolean;
FIsTabGrid: Boolean;
protected
procedure NewKeyDown(Sender : TObject;var Key : word;Shift : TShiftState);
procedure NewKeyPress(Sender : Tobject;var Key : char);
public
constructor Create(AOwner : TComponent); override;
published
property Active : boolean read FActive write FActive
default false;
property Options : TMoveOptions read FOptions write FOptions
default [moEnter,moUpDn];
property EditNoBeep : boolean read FEditNoBeep write FEditNoBeep
default true;
end;
procedure Register;
implementation
//-----------------------------------------------------------------------------
procedure Register;
begin
RegisterComponents('HomeMade', [TDosMove]);
end;
//-----------------------------------------------------------------------------
constructor TDosMove.Create(AOwner : TComponent);
var
Loop : integer;
begin
// First check to see no other TDosMove exists on the form
for Loop:=0 to AOwner.ComponentCount-1 do
if AOwner.Components[Loop] is TDosMove then raise
EInvalidOperation.Create('TDosMove can have only one instance per form');
// Create component and set default properties
inherited Create(AOwner);
FActive := True;
FOptions := [moEnter,moUpDn];
FEditNoBeep := True;
FIsTabGrid := False;
// Intercept with OnKeyDown event and OnKeyPress event of 'Owner'
(AOwner as TForm).KeyPreview := True;
FOwnerKeyDown := (AOwner as TForm).OnKeyDown;
(AOwner as TForm).OnKeyDown := NewKeyDown;
FOwnerKeyPress := (AOwner as TForm).OnKeyPress;
(AOwner as TForm).OnKeyPress := NewKeyPress;
end; // Create
//-----------------------------------------------------------------------------
procedure TDosMove.NewKeyDown(Sender : TObject;var Key : word;
Shift : TShiftState);
begin
// Call owner OnKeyDown if it's assigned
if Assigned(FOwnerKeyDown) then FOwnerKeyDown(Sender,Key,Shift);
if FActive then
begin
// true if last active control is TCustomEdit and above
FLastWasEdit:=(Owner as TForm).ActiveControl is TCustomEdit;
if (FOptions <> []) and (Shift = []) then
begin
if (Owner as TForm).ActiveControl is TCustomGrid then
begin
if (Key = VK_RETURN) then
begin
Key := VK_TAB;
FIsTabGrid := True;
end;
end else
begin
// Handle the specials keys
if ((Key = VK_DOWN) and (moUpDn in FOptions)) or
((Key = VK_RETURN) and (moEnter in FOptions)) then
(Owner as TForm).Perform(WM_NEXTDLGCTL, 0, 0)
else if (Key = VK_UP) and (moUpDn in FOptions) then
(Owner as TForm).Perform(WM_NEXTDLGCTL, 1, 0);
end;
end; // if Options<>[] ...
end; // if FActive ...
end; // NewKeyDown
//-----------------------------------------------------------------------------
procedure TDosMove.NewKeyPress(Sender : TObject;var Key : char);
begin
// Call owner OnKeyPress if it's assigned
if assigned(FOwnerKeyPress) then FOwnerKeyPress(Sender,Key);
// Handle 'Enter' key that makes Edits beep
if FActive then
begin
if FEditNoBeep and FLastWasEdit and (Key = #13) then Key := #0;
if FIsTabGrid then
begin
FIsTabGrid := False;
Key := #0;
end;
end; // if FActive ...
end; // NewKeyPress
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -