检查是否按下了 DELETE 键? [英] Check if DELETE key is pressed?

查看:56
本文介绍了检查是否按下了 DELETE 键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

使用 e.keyValue 检查 DELETE 键需要的 keyValue 是多少?

What is the keyValue I need for checking for the DELETE key using e.keyValue?

推荐答案

KeyEventArgs 对象包含一个名为KeyCode",您可以将其与 "" 枚举.

The KeyEventArgs object contains a member called "KeyCode" that you can compare to the "Keys" enumeration.

请注意,如果某些键由默认窗口系统处理,则它们可能不会引发 KeyDown 事件.我不确定,我现在无法检查,但您可能无法获得 Tab、Delete、Enter 等键的 KeyDown 事件.

Note that certain keys may not raise the KeyDown event if they are handled by the default windowing system. I'm not sure, and I can't check it right now, but you may not get the KeyDown event for keys like Tab, Delete, Enter, etc.

你通常可以这样做(这是 C#,不是 VB,但应该是类似的):

You can usually do something like this (this is C#, not VB, but should be similar):

public void MyControl_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Delete)
    {
        // delete was pressed
    }
}

这篇关于检查是否按下了 DELETE 键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆