探讨一个小问题:如何以回车键替代tab键跳到下一个编辑框。(0分)

  • 主题发起人 主题发起人 myyzg
  • 开始时间 开始时间
onkeypress envent
if key=#13 then
yourcontorl.getfoucs;
 
这问题好象以前提过。
在控件的OnkeyDown事件中写
if key = VK_Return then
keybd_event( VK_TAB, MapVirtualKey( VK_TAB, 0 ), 0 , 0 );
 
首先,设置窗体的KeyPreview属性值为True;
然后,在窗体的事件onKeyDown中添入:
if key=13 then
key:=9;
完事!
 
下面是个这样的控见,把它加到你的系统中,放到你的form上就可以了。
unit Tabenter;
interface
uses SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls;
type
TkEnterAsTab = class(TSpeedButton)
private
FEnterAsTab : boolean;
protected
procedure CMDialogKey(var Message: TCMDialogKey);
message CM_DIALOGKEY;
procedure Paint;
override;
public
constructor Create( AOwner : TComponent );
override;
published
property EnterAsTab : boolean read FEnterAsTab write FEnterAsTab default True;
end;

procedure Register;
implementation
constructor TkEnterAsTab.Create( AOwner : TComponent );
begin
inherited Create(AOwner);
FEnterAsTab := True;
if not (csDesigning in ComponentState) then
begin
Enabled := False;
Visible := False;
end else
Caption := 'ET';
end;

procedure TkEnterAsTab.CMDialogKey(var Message : TCMDialogKey);
begin
if (GetParentForm(Self).ActiveControl is TButton {Control}) then
inherited
else
if (Message.CharCode = VK_RETURN) and (EnterAsTab) then
begin
GetParentForm(Self).Perform(CM_DialogKey, VK_TAB, 0);
Message.Result := 1;
end else
inherited;
end;

procedure TkEnterAsTab.Paint;
begin
if (csDesigning in ComponentState) then
begin
Width := 27;
Height := 27;
end;
inherited Paint;
end;

procedure Register;
begin
RegisterComponents('Samples', [TkEnterAsTab]);
end;
end.

 
接受答案了.
 
也可用postmessage(hanlde,WM_KEYDOWN,VK_TAB,0),来实现
 
后退
顶部