?
Solved

Enter and Edit Box

Posted on 2006-05-24
7
Medium Priority
?
276 Views
Last Modified: 2010-04-05
I have 1 edit box and button. Now i want that when user writes in edit box and hits ENTER from the keyboard that it is the same as he has hit the button. How to do this ?
0
Comment
Question by:65zgtre45rr
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
RickJ earned 1600 total points
ID: 16757085
Use the OnKeyDown event of the EditBox....

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Hello') ;
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_RETURN then
    Button1Click(Sender) ;
end;
0
 
LVL 9

Assisted Solution

by:sun4sunday
sun4sunday earned 80 total points
ID: 16757876
YOu can easily do with out writing a single piece of code using bit button
Go to tools tab and additional > drop a BitBtn  

Set the button's default property to true.

Thats all.. When ever pressing the enter key automatially press the BitBtn

Hope this helps

sun4sunday
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 320 total points
ID: 16758315
regarding RickJ's code. it will not work in case you are creating stuff dynamically and in another few rare situations. somethgin like this though should work on any ocasion (except if the user fogets his/her finger on the neter key):

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Hello') ;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
    button1.click;// alows dynamic component creation AND works even if the button doesn't have an event associated in the current unit ;) (allows assigning dynamically events to the button)
end;


regarding sun4sunday's code, it is a very good solution, IF and only if you have one edit and one button :)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:sun4sunday
ID: 16759101
>>regarding sun4sunday's code, it is a very good solution, IF and only if you have one edit and one button :)

ciuly,

this will work with any number of edit boxes and any number of buttons on the same form.
Only thing make default property to true for the button which requried to get trigger when pressing enter key.

sun4sunday
0
 
LVL 28

Expert Comment

by:2266180
ID: 16759174
sorry for not being clear enough: if I have 2 editboxes and 2 buttons and I want both edits to trigger it's own button.. then it will not work. you can only have one default button on a form (if you have more, only the first one in respect to taborder will work as default)
0
 
LVL 9

Expert Comment

by:sun4sunday
ID: 16759302
>> I want both edits to trigger it's own button

ciuly

this case is right....Communication    g     a      p    ;)   'confsuoin' !!!
cheers

sun4sunday

0
 
LVL 8

Expert Comment

by:RickJ
ID: 16765766
Thanks.
Glad I could help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question