Topic: Set Cursor Focus and Enter Key Handling

How am i able to translate the following script for MVD.

I wish to press enter and to set focus to the next textbox.



Procedure textBox1_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Enter)
      {
        textBox2.Focus();
      }
    }

Re: Set Cursor Focus and Enter Key Handling

Hello chrysoco

CAn this be a clue for you ?

procedure frmEmployee_Ctrl_OnKeyDown (Sender: string; var Key: Word; Shift, Alt, Ctrl: boolean);
begin
    if Key=13 then frmEmployee.SetFocusNextControl;
end;

   
begin
    frmEmployee.bSave.Default := False;
end.

JB

Re: Set Cursor Focus and Enter Key Handling

Thanks it worked a lot

Re: Set Cursor Focus and Enter Key Handling

Please uplaod a sample.

JUST LEARNING, O GOD HELP ME.

Re: Set Cursor Focus and Enter Key Handling

Hi,
Attached is an example of using the 'enter' key to simulate the 'tab' key.
Derek.

Post's attachments

Attachment icon enterkey.zip 335.63 kb, 546 downloads since 2019-08-11 

Re: Set Cursor Focus and Enter Key Handling

THANKS, SIR, ONE QUESTION MORE,
Why KEYPREVIEW is needed...
//** don't' forget to set 'key preview = true' on Form1 object properties

JUST LEARNING, O GOD HELP ME.

Re: Set Cursor Focus and Enter Key Handling

Hi,
As I understand it, setting 'keypreview' to true basically allows you to process an action (in this example, using the 'enter' key) AT THE FORM LEVEL instead of writing code for each individual object on that form.
Derek.

Re: Set Cursor Focus and Enter Key Handling

OK, now I understand, Sorry I ask too much question.

JUST LEARNING, O GOD HELP ME.

Re: Set Cursor Focus and Enter Key Handling

Hello Derek, Hello Asifmute

This is how Embarcadero Rad XE (language from which MVD flows) defines the use of the KeyPreview statement:

If KeyPreview is true, keyboard events occur on the form before they occur on the active control. (The active control is specified by the ActiveControl property.) 

If KeyPreview is false, keyboard events occur only on the active control.

Navigation keys (Tab, BackTab, the arrow keys, and so on) are unaffected by KeyPreview because they do not generate keyboard events. Similarly, when a button has focus or when its Default property is true, the Enter key is unaffected by KeyPreview because it does not generate a keyboard events.

KeyPreview is false by default.

Have a good day

JB

Re: Set Cursor Focus and Enter Key Handling

THANKS TO @jean.brezhonek.
Your answer is really explanatory.

JUST LEARNING, O GOD HELP ME.