KeyPress设为True,加入下列代码拦截击键: Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char); Begin if key=#13 then { 判断是按执行键} Begin key:=#0; perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件} End;
DosMove v1.02这个控件 可以跳不同panel之间的控件,很好用的,带愿代码的
//----------------------------------------------------------------------------- // 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 // [email protected] //----------------------------------------------------------------------------- // Modify Version 1.02c // Designer : DEVEN // E-Mail: [email protected] // unit DosMove;interfaceuses 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; // NewKeyPressend.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (ActiveControl <> nil) and (Key = VK_RETURN) then Begin if ssShift in Shift then Begin if ActiveControl is TMemo then begin ; end else ActiveControl := FindNextControl(ActiveControl as TWinControl,False, True,False) End else ActiveControl := FindNextControl(ActiveControl as TWinControl, True, True, False); End; end;
Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char);
Begin
if key=#13 then { 判断是按执行键}
Begin
key:=#0;
perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件}
End;
可以跳不同panel之间的控件,很好用的,带愿代码的
// 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
// [email protected]
//-----------------------------------------------------------------------------
// Modify Version 1.02c
// Designer : DEVEN
// E-Mail: [email protected]
//
unit DosMove;interfaceuses
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; // NewKeyPressend.
Shift: TShiftState);
begin
if (ActiveControl <> nil) and (Key = VK_RETURN) then
Begin
if ssShift in Shift then
Begin
if ActiveControl is TMemo then
begin
;
end
else
ActiveControl := FindNextControl(ActiveControl as TWinControl,False, True,False)
End
else
ActiveControl := FindNextControl(ActiveControl as TWinControl, True, True, False);
End;
end;