回车键(Enter键)进行快速判断
在其位,谋其政。做一颗螺丝钉,就发挥螺丝钉稳稳当当的功能。做软件,为了尽可能地为用户着想,增强用户体验度,增添附加值,进一步做些努力。
本文介绍我在机房收费系统中的回车键实现上下机操作。以VB.NET作示例,而回车键(Enter键)的判断代码在其他语法也是适用的。
判断回车键的代码为:e.KeyCode = Keys.Enter或e.keyCode = “13”
实例:
'输入卡号,回车键(“Enter”键),上下机Private Sub txtCardID_KeyDown(sender As Object, e As KeyEventArgs) Handles txtCardID.KeyDownDim UpDown As String = vbNullDim i As Integer = 1Dim myList As List(Of Entity.MainEntity)Dim logon_en As New Entity.LogonEntityDim updoing_en As New Entity.MainEntityDim main_bll As New BLL.MainBLL'捕获界面卡号logon_en.CardID = txtCardID.Text.Trimlogon_en.State = "使用"myList = main_bll.select_doing()'调用查询注册表方法,传入注册表实体,返回注册表实体将原来的实体覆盖logon_en = main_bll.select_logon(logon_en)'判断泛型(实体集)中实体个数If myList.Count > 0 ThenDo While i < myList.Count Or i = myList.Countupdoing_en = myList.Item(i - 1)'核查“卡号”是否在【正在上机表】中If updoing_en.CardID = txtCardID.Text.Trim ThenUpDown = "Down"Exit DoEnd Ifi = i + 1LoopIf UpDown = "Down" Then'标记保持不变UpDown = "Down"ElseIf logon_en.CardID = txtCardID.Text.Trim Then'修改标记UpDown = "Up"Else'清空标记UpDown = "Null"End IfElse'【正在上机表】无数据,那就直接,试试“上机”,按正常“上机”的程序走UpDown = "Up"End If'如果单击的按钮为“Enter”键(回车键)If e.KeyCode = Keys.Enter ThenIf UpDown = "Up" ThenbtnUp_Click(sender, e) '等价于 = 敲击“上机”按钮ElseIf UpDown = "Down" ThenbtnDown_Click(sender, e) '等价于 = 敲击“下机”按钮End IfEnd IfEnd Sub
本实例用到了按键代换,就是相当于按下A键,进行判断,在若符合条件a等价于按了A键;若符合条件b则等价于按了B键。