文本框中回车转换成TAB跳转(100分求解) ( 积分: 8 )

  • 主题发起人 主题发起人 Baisir
  • 开始时间 开始时间
B

Baisir

Unregistered / Unconfirmed
GUEST, unregistred user!
我在编写一个文本框的控件。
我想在输入框中点回车键,就等于点下了TAB键,怎么实现?
帮忙,解答出来我另赠100分
我有个死问题无人解答,你上去回复了,我就加给你。
地址:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3034208
 
我在编写一个文本框的控件。
我想在输入框中点回车键,就等于点下了TAB键,怎么实现?
帮忙,解答出来我另赠100分
我有个死问题无人解答,你上去回复了,我就加给你。
地址:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3034208
 
先将窗体的KeyPreview属性设为True。然后在FormKeyPress事件中加入以下代码:

procedure TF_openaccount.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
selectnext(activecontrol as twincontrol,true,true);
key:=#0;
end;
end;



帮助信息:
VCL Reference
SelectNext method (TWinControl)

TWinControl See also

Moves the input focus from the current child control to the next one in the tab order.

Delphi syntax:

procedure SelectNext(CurControl: TWinControl; GoForward, CheckTabStop: Boolean);

C++ syntax:

void __fastcall SelectNext(TWinControl* CurControl, bool GoForward, bool CheckTabStop);

Description

Call SelectNext to move the child control focus. SelectNext selects the first child that follows or precedes CurControl in the tab order and that meets the criteria specified in the other parameters.

The GoForward parameter controls the direction of the search. If GoForward is true, FindNextControl searches forward through the child controls in tab order. If GoForward is false, SelectNext searches backward through the controls. The search wraps past the end of the collection back to CurControl.

The CheckTabStop parameter controls whether the control SelectNext finds must be a tab stop. If CheckTabStop is true, the returned control must have its TabStop property set to true, or the search for the next control continues.

If a child control matches the search criteria, that control obtains the focus. If no such child control is found, the focus remains unchanged.
 
将窗体的keypreview:=true

{按回车件使下一控件得到焦点}
procedure CheckFormKeyPress(Aform:Tform;Sender: TObject; var Key: Char);
begin
if Key=#13 then
if not (Sender is TButton) then
begin
key:=#0;
Aform.perform(WM_NEXTDLGCTL,0,0); {移动到下一个控件}
end;
end;
 
我编写的是个控件,完全是从edit继承过来的。
别的什么都没有。能用的资源只能是这个控件。
我作的程序布局复杂,窗体上用这招不好使。
还是想在控件一下功夫。
 
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
keybd_event( VK_Tab, 0, 0,0 );
keybd_event( VK_Tab, 0, KEYEVENTF_KEYUP, 0);
key:=#0;
end;
end;
 
谢谢 tswhq,,接受答案,请到我给联接的另一个问题,100分赠。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部