Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I feel like an idiot asking this...

Ok. This should be really simple, but I'm going crazy figuring it out so please help.
You know how if you press enter in an edit box (single line) sometimes it will cause a "default" button to be pressed? I know how to do this in a dialog box, it's easy, but this happens even outside of dialog boxes - I see it all the time in different applications, even right here in Internet Explorer, on Altavista I can type my search and then just hit enter and it automatically selects the "search" button.
Well... how the heck is this done?!? I've been searching through the MSDN for the last hour and I've tried everything I can think of, but I can't get it to work - edit boxes send keyboard presses that they don't process to DefWindowProc, so my parent window that the edit box is in never even sees the keypress. What can I do to fix this, I'm going nuts?
Note - key point, I am not using a dialog box, but a regular WS_OVERLAPPED window. I have to for design reasons.

Comments

  • Sephiroth2Sephiroth2 Posts: 423Member
    : Ok. This should be really simple, but I'm going crazy figuring it out so please help.
    : You know how if you press enter in an edit box (single line) sometimes it will cause a "default" button to be pressed? I know how to do this in a dialog box, it's easy, but this happens even outside of dialog boxes - I see it all the time in different applications, even right here in Internet Explorer, on Altavista I can type my search and then just hit enter and it automatically selects the "search" button.
    : Well... how the heck is this done?!? I've been searching through the MSDN for the last hour and I've tried everything I can think of, but I can't get it to work - edit boxes send keyboard presses that they don't process to DefWindowProc, so my parent window that the edit box is in never even sees the keypress. What can I do to fix this, I'm going nuts?
    : Note - key point, I am not using a dialog box, but a regular WS_OVERLAPPED window. I have to for design reasons.
    :
    There are at least two ways to do this.
    1. change the edit box routine to point to your own
    OR
    2. trap the message in your main message loop

  • HasanHasan Posts: 74Member
    Hello there.

    If I have understood your question correctly then you can do the following:

    When the user hits the enter/return key you can pass on the focus to the next control, which will be a button in this case and then press the button using the code.

    Use the following code in Delphi

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
    IF Key = #13 THEN
    begin
    button1.SetFocus;
    button1.Click;
    end;
    end;


    I really hope that helps.



    [size=2][red]"The biggest fool of all the foolish fools is BettyBoy. You know who you are!" :-D[/red][/size]


  • Sephiroth2Sephiroth2 Posts: 423Member
    : Hello there.
    :
    : If I have understood your question correctly then you can do the following:
    :
    : When the user hits the enter/return key you can pass on the focus to the next control, which will be a button in this case and then press the button using the code.
    :
    : Use the following code in Delphi
    :
    : procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    : begin
    : IF Key = #13 THEN
    : begin
    : button1.SetFocus;
    : button1.Click;
    : end;
    : end;
    :
    :
    : I really hope that helps.
    :
    :
    :
    : [size=2][red]"The biggest fool of all the foolish fools is BettyBoy. You know who you are!" :-D[/red][/size]
    :
    :

    Obviously he can't use the code in Delphi because he doesn't program in Delphi.

Sign In or Register to comment.