enter键键值
We know that, generally, pressing the Tab key moves the input focus to next control and Shift-Tab to previous in the tab order of the form. When working with Windows applications, some users intuitively expect the Enter key to behave like a Tab key.
我们知道,通常,按Tab键会将输入焦点移至窗体的Tab键顺序中的下一个控件,而Shift-Tab键则移至上一个控件。 使用Windows应用程序时 ,某些用户直观地期望Enter键的行为类似于Tab键。
There is a lot of third-party code for implementing better data entry processing in Delphi. Here are a few of the best methods out there (with some modifications).
有很多第三方代码可用于在Delphi中实现更好的数据输入处理。 这里是一些最佳方法(经过一些修改)。
Examples below are written with the assumption that there is no default button on the form. When your form contains a button whose Default property is set to True, pressing Enter at runtime executes any code contained in the button's OnClick event handler.
下面的示例是在假定表单上没有默认按钮的情况下编写的。 当您的表单包含其Default属性设置为True的按钮时 ,在运行时按Enter将执行按钮的OnClick事件处理程序中包含的所有代码。
输入为标签 ( Enter as Tab )
The next code causes Enter to behave like Tab, and Shift+Enter like Shift+Tab:
下面的代码使Enter的行为类似于Tab,而Shift + Enter的行为类似于Shift + Tab:
~~~~~~~~~~~~~~~~~~~~~~~~~procedure TForm1.Edit1KeyPress (Sender: TObject; var Key: Char) ;begin If Key = #13 Then Begin If HiWord(GetKeyState(VK_SHIFT)) <> 0 then SelectNext(Sender as TWinControl,False,True) else SelectNext(Sender as TWinControl,True,True) ; Key := #0 end;end;~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~程序TForm1.Edit1KeyPress(Sender:TObject; var Key:Char);开始于Key =#13则开始于HiWord (GetKeyState(VK_SHIFT))<> 0然后选择Next(发送者为TWinControl,False,True),否则为SelectNext(发送者为TWinControl,True,True); 键:=#0 end; end; ~~~~~~~~~~~~~~~~~~~~~~~~~
在DBGrid中 ( in DBGrid )
If you want to have similar Enter (Shift+Enter) processing in DBGrid:
如果要在DBGrid中进行类似的Enter(Shift + Enter)处理:
~~~~~~~~~~~~~~~~~~~~~~~~~procedure TForm1.DBGrid1KeyPress (Sender: TObject; var Key: Char) ;begin If Key = #13 Then Begin If HiWord(GetKeyState(VK_SHIFT)) <> 0 then begin with (Sender as TDBGrid) do if selectedindex > 0 then selectedindex := selectedindex - 1 else begin DataSource.DataSet.Prior; selectedindex := fieldcount - 1; end; end else begin with (Sender as TDBGrid) do if selectedindex < (fieldcount - 1) then selectedindex := selectedindex + 1 else begin DataSource.DataSet.Next; selectedindex := 0; end; end; Key := #0 end;end;~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~过程TForm1.DBGrid1KeyPress(Sender:TObject; var Key:Char);开始于Key =#13则开始于HiWord (GetKeyState(VK_SHIFT))<> 0然后以(Sender as TDBGrid)开始,如果selectedindex> 0然后selectedindex:= selectedindex-1否则开始DataSource.DataSet.Prior; selectedindex:= fieldcount-1; 结束; 结束,否则以(Sender as TDBGrid)开头,如果selectedIndex <(fieldcount-1),然后selectedIndex:= selectedindex + 1,否则开始DataSource.DataSet.Next; selectedindex:= 0; 结束; 结束; 键:=#0 end; end; ~~~~~~~~~~~~~~~~~~~~~~~~~
有关Delphi应用程序的更多信息 ( More Info on Delphi Applications )
Keyboard Symphony Get familiar with the OnKeyDown, OnKeyUp, and onKeyPress event procedures to respond to various key actions or handle and process ASCII characters along with other special purpose keys.
键盘交响曲熟悉OnKeyDown,OnKeyUp和onKeyPress事件过程,以响应各种键操作或处理和处理ASCII字符以及其他专用键。
What Does #13#10 Stand for, in Delphi Code? If you are wondering what those characters stand for, here's the answer.
#13#10在Delphi Code中代表什么? 如果您想知道这些字符代表什么,这里就是答案。
翻译自: https://www.thoughtco.com/make-the-enter-key-work-like-tab-1058389
enter键键值