English 中文(简体)
c) 部分 • 如何利用该进程来捕获诸如“Tab”、“Up”等特殊特性
原标题:c# How to use the ProcessDialogKey to capture special characters like "Tab", "Up" etc
  • 时间:2009-09-23 16:31:24
  •  标签:

我想在批评“Tab”时进行登记,但可以说明如何使用该程序。

这就是:

this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Keypress);    

private void Keypress(object sender, KeyPressEventArgs e)
{
    MessageBox.Show("button: " + e.KeyChar);
}

这只能捕获固定的果园,但还需要“Tab”等其它东西。

因此,我研究了一条轨道,发现许多人已经利用了该程序,但认为如何使用它并不确定。

这里指的是:

protected  override bool ProcessDialogKey(Keys keyData)
{
    switch (keyData)
    {
        case Keys.Up:
            MessageBox.Show("Up");
            break;
        case Keys.Tab:
            MessageBox.Show("Tab");
            break;
        default:
            break;         
    }
}

我发现错误: Project.frm_test.ProcessDialogKey(System.Windows.Forms.Keys): 未发现高于的任何适当方法

什么是错了?

And bear with me... i m used to php :) So i m kinda new to c# :)

最佳回答

你的守则正在发挥作用,你的信息箱只是展示一个表象,即空白空间。

工作:

MessageBox.Show("button: " + (int) e.KeyChar); 

EDIT: Otherwise look at this code:

public Form1()
{
    InitializeComponent();

    this.KeyPress += new KeyPressEventHandler(this.Form1_KeyPress);
    this.KeyDown += new KeyEventHandler(this.Form1_KeyDown);            
}

// Keypress only handles keys in the ascii range
private void Form1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    MessageBox.Show("KeyPress: " + (int) e.KeyChar); 
}

// Keydown will work for all keys
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    MessageBox.Show("KeyDown: " + e.KeyCode); 
}          
问题回答

暂无回答




相关问题
热门标签