delphi中 按钮输入 多个编辑框的选择
如图,Button作用是往编辑框edit中输入一个数据,比如12。如何在按下按钮后在光标所在的编辑框内输入数据?这样只能输入一次数据,然后光标就没有了。要多按几次按钮,e...
如图,Button作用是往编辑框edit中输入一个数据,比如12。如何在按下按钮后 在光标所在的编辑框内输入数据?
这样只能输入一次数据,然后光标就没有了。要多按几次按钮,edit里可以重复输入呢?那该怎么做? 展开
这样只能输入一次数据,然后光标就没有了。要多按几次按钮,edit里可以重复输入呢?那该怎么做? 展开
展开全部
根据你的要求修改了一下,再试试:
=====unit1.pas文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CurEdit:TEdit;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if TEdit(Form1.ActiveControl)=Edit1 then
CurEdit := Edit1
else if TEdit(Form1.ActiveControl)=Edit2 then
CurEdit := Edit2
else if TEdit(Form1.ActiveControl)=Edit3 then
CurEdit := Edit3;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if CurEdit<>nil then begin
CurEdit.Text := '12';
CurEdit.SetFocus; // 加上这个看怎么样!
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CurEdit := nil;
end;
end.
=====unit1.dfm文件:
object Form1: TForm1
Left = 293
Top = 266
Width = 251
Height = 141
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 16
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 16
Top = 40
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'
end
object Edit3: TEdit
Left = 16
Top = 72
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit3'
end
object Button1: TButton
Left = 152
Top = 56
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 3
OnClick = Button1Click
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 160
Top = 8
end
end
=====unit1.pas文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CurEdit:TEdit;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if TEdit(Form1.ActiveControl)=Edit1 then
CurEdit := Edit1
else if TEdit(Form1.ActiveControl)=Edit2 then
CurEdit := Edit2
else if TEdit(Form1.ActiveControl)=Edit3 then
CurEdit := Edit3;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if CurEdit<>nil then begin
CurEdit.Text := '12';
CurEdit.SetFocus; // 加上这个看怎么样!
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CurEdit := nil;
end;
end.
=====unit1.dfm文件:
object Form1: TForm1
Left = 293
Top = 266
Width = 251
Height = 141
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 16
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 16
Top = 40
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'
end
object Edit3: TEdit
Left = 16
Top = 72
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit3'
end
object Button1: TButton
Left = 152
Top = 56
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 3
OnClick = Button1Click
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 160
Top = 8
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询