关于Edit与Button的问题.请教请教

littlexin 2003-04-07 04:13:35
请问一下.如何可以使在Edit中按回车键直接调用Button中的OnClick事件?
...全文
31 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pairs 2003-04-07
  • 打赏
  • 举报
回复
if Key=#13 then
Button1Click(nil);
redlegend_126_com 2003-04-07
  • 打赏
  • 举报
回复
KeyDown事件中:
if Key=#13 then
Button1.Click;
Taken 2003-04-07
  • 打赏
  • 举报
回复
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
Button1.Click;
end;
zqc-tutorial 2003-04-07
  • 打赏
  • 举报
回复
楼上分析的好,
如果Button1Click(Sender: TObject)同时处理了其他按钮或者其他控件的OnClick事件,
这时S应该Button1Click(Button1)或者Button1.Click,前者要注意参数问题,
后者则不用考虑了。
ahjoe 2003-04-07
  • 打赏
  • 举报
回复
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
Button1.Click();
end;
yyfhz 2003-04-07
  • 打赏
  • 举报
回复
同意楼上的,不过使用Button1Click(self)的要当心了,
1.Button1.OnClick可以不是Button1Click的,
2.Sender参数一般是指事件接受者,如Button1自己
3.调用Button1.Click会有按钮被按下的显示效果:)
jianyuzhu 2003-04-07
  • 打赏
  • 举报
回复
KeyDown事件中:
if Key=#13 then
Button1.Click;
ziqing 2003-04-07
  • 打赏
  • 举报
回复
来晚了
jan2002 2003-04-07
  • 打赏
  • 举报
回复
if Key=#13 then
Button1Click(self);

ourme 2003-04-07
  • 打赏
  • 举报
回复
赞成楼上
cjfzy 2003-04-07
  • 打赏
  • 举报
回复
if Key=#13 then
Button1Click(Button1);
caoyq 2003-04-07
  • 打赏
  • 举报
回复
KeyPress事件中:
if Key=#13 then
Button1.Click;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧