enter键键值_使Enter键像选项卡一样工作

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 )

翻译自: https://www.thoughtco.com/make-the-enter-key-work-like-tab-1058389

enter键键值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值