Visual Basic.NET 2008-捕获VB.NET中的键

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中捕获密钥”或其他所需的名称。

Figure 1 - Name the project
Step 3第三步

  Customize the form in anyway that you want.

无论如何都可以自定义表单。

Figure 2 - Customize the form
Step 4第4步

  Add two labels and name them "lblKeyCode" and "lblKeyValue".

添加两个标签,并将它们分别命名为“ lblKeyCode”和“ lblKeyValue”。

Figure 3 - Add two labels
Step 5第5步

  Select the form, enter the list of handlers and double-click the "KeyDown" handler.

选择表单,输入处理程序列表,然后双击“ KeyDown”处理程序。

Figure 4 - Create a "KeyDown" handler
Step 6第6步

  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步骤7

  Press 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值