如何在Delphi中用回车键切换输入焦点
答案:2 悬赏:60 手机版
解决时间 2021-12-25 23:20
- 提问者网友:雾里闻花香
- 2021-12-25 05:33
如何在Delphi中用回车键切换输入焦点
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-12-25 06:29
回车后转移焦点:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then edit2.SetFocus;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then button1.SetFocus;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then edit2.SetFocus;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then button1.SetFocus;
end;
end.
全部回答
- 1楼网友:十鸦
- 2021-12-25 07:36
将窗体的keypreview:=true{按回车件使下一控件得到焦点}procedure checkformkeypress(aform tobject; var key: char);begin if key=#13 then if not (sender is tbutton) then begin key0; aform.perform(wm_nextdlgctl,0,0); {移动到下一个控件} end;end;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯