Hello Experts Exchange Users!
您好专家交流用户!
This is my first tutorial, so I hope that you like it!
这是我的第一篇教程,希望您喜欢!
Goal : Create a program to get the keys entered into the form
目标:创建一个程序以将密钥输入到表单中
Programming Language : Visual Basic.NET 2008 SP1
编程语言:Visual Basic.NET 2008 SP1
Step 1第1步The first thing that we must do to reach our goal is create a new project. This can be done by clicking File > New Project or by pressing Control and N on your keyboard.
为了实现目标,我们必须做的第一件事就是创建一个新项目。 可以通过单击文件>新建项目或通过按键盘上的Control和N来完成。
Step 2第2步Name the project "Capturing Keys in VB.NET" or anything else that you want.
将项目命名为“在VB.NET中捕获密钥”或其他所需的名称。
Customize the form in anyway that you want.
无论如何都可以自定义表单。
Add two labels and name them "lblKeyCode" and "lblKeyValue".
添加两个标签,并将它们分别命名为“ lblKeyCode”和“ lblKeyValue”。
Select the form, enter the list of handlers and double-click the "KeyDown" handler.
选择表单,输入处理程序列表,然后双击“ KeyDown”处理程序。
In the "KeyDown" handler, you must put the following code:
在“ KeyDown”处理程序中,必须输入以下代码:
lblKeyCode.Text = e.KeyCode.ToString
lblKeyValue.Text = e.KeyValue.ToString
Explanation for Step 6步骤6的说明
The code "lblKeyCode.Text = e.KeyCode.ToString" will set the first label to the internal key name. (eg. "A" or "Delete")
代码“ lblKeyCode.Text = e.KeyCode.ToString”将第一个标签设置为内部键名称。 (例如,“ A”或“删除”)
The code "lblKeyValue.text = e.KeyValue.ToString" will set the second label to the value of the key (eg. "19" or "49")
代码“ lblKeyValue.text = e.KeyValue.ToString”将第二个标签设置为键的值(例如“ 19”或“ 49”)
Step 7步骤7Press the debug button and press any key on your keyboard
按调试按钮,然后按键盘上的任何键
The value of the labels should change, depending on which key you press
标签的值应更改,具体取决于您按的键
- Daniel Sage
-Daniel Sage
翻译自: https://www.experts-exchange.com/articles/1784/Visual-Basic-NET-2008-Capturing-Keys-in-VB-NET.html