110,580
社区成员
发帖
与我相关
我的任务
分享
private void button_KeyUp(object sender, KeyEventArgs e)
{
flag = false;
}
public Form1()
{
InitializeComponent();
button1.KeyUp += new KeyEventHandler(button_KeyUp);
button2.KeyUp += new KeyEventHandler(button_KeyUp);
button1.KeyPress += new KeyPressEventHandler(button_KeyPress);
button2.KeyPress += new KeyPressEventHandler(button_KeyPress);
}
private void button_KeyUp(object sender, KeyEventArgs e)
{
flag = false;
if (32 == e.KeyValue)
{
flag = true;
}
else
{
label2.Text = e.KeyValue.ToString();
}
}
什么意思啊?KeyPress-->KeyDown-->Click-->KeyUp。程序调用应该是走这个步骤(我调试的时候是这样)。所以你说的截获是什么意思??意思是KeyDown事件有可能不触发?KeyUp一定触发吗? [quote=引用 8 楼 yan_hyz 的回复:] 在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了
什么意思啊?KeyPress-->KeyDown-->Click-->KeyUp。程序调用应该是走这个步骤(我调试的时候是这样)。所以你说的截获是什么意思??意思是KeyDown事件有可能不触发?KeyUp一定触发吗? [quote=引用 8 楼 yan_hyz 的回复:] 在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了
什么意思啊?KeyPress-->KeyDown-->Click-->KeyUp。程序调用应该是走这个步骤(我调试的时候是这样)。所以你说的截获是什么意思??意思是KeyDown事件有可能不触发?KeyUp一定触发吗? 在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了
[quote=引用 10 楼 NCScan 的回复:] [quote=引用 8 楼 yan_hyz 的回复:] 在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了
程序目的描述: 按night键会出现“good night”,而按afternoon键会出现"good afternoon".我如果选中night键之后按空格键,不会出现”good night".按回车键的时候会出现"good night". 问题描述: 我现在按过空格键之后,不会出现"good night",但是再按回车键的时候不会出现"good night".我进行调试,发现是button的触发事件button.keyPress不触发了。直接进入button1_Click()中了。
this.button1.keyPress += new System.EventHandler(this.button1_Click);
但是 个人认为。由于是系统的 原因。除非指定了 键盘空格或者回车特定事件外。默认系统还是会发出和鼠标左键同样的命令 单击或者双击。 LZ可以选中桌面任何一个图标,然后按下回车键![quote=引用 8 楼 yan_hyz 的回复:]在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Button的空格回车响应 { public partial class FormMain : Form { public FormMain() { InitializeComponent(); } private void btn_Night_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { this.label1.Text = "Night:按下空格"; //e.Handled = true; //再此时按下回车无效 //e.Handled = false; //再此时按下回车无效 //e.SuppressKeyPress = true; } if (e.KeyCode == Keys.Enter) { this.label1.Text = "Night:按下回车"; //MessageBox.Show("回车"); //e.Handled = true; } else { this.label1.Text = "????"; } } private void btn_Night_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { this.label1.Text = "Up_空格"; //e.Handled = true; } else if (e.KeyCode == Keys.Enter) { this.label1.Text = "Up_回车"; //e.Handled = true; } } private void btn_Night_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 32) { this.label1.Text = "Press_空格"; } else if (e.KeyChar == 44) { this.label1.Text = "Press_回车"; } } } }
什么意思啊?KeyPress-->KeyDown-->Click-->KeyUp。程序调用应该是走这个步骤(我调试的时候是这样)。所以你说的截获是什么意思??意思是KeyDown事件有可能不触发?KeyUp一定触发吗? 在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了
在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Button的空格回车响应 { public partial class FormMain : Form { public FormMain() { InitializeComponent(); } private void btn_Night_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { this.label1.Text = "Night:按下空格"; //e.Handled = true; //再此时按下回车无效 //e.Handled = false; //再此时按下回车无效 //e.SuppressKeyPress = true; } if (e.KeyCode == Keys.Enter) { this.label1.Text = "Night:按下回车"; //MessageBox.Show("回车"); //e.Handled = true; } else { this.label1.Text = "????"; } } private void btn_Night_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { this.label1.Text = "Up_空格"; //e.Handled = true; } else if (e.KeyCode == Keys.Enter) { this.label1.Text = "Up_回车"; //e.Handled = true; } } private void btn_Night_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 32) { this.label1.Text = "Press_空格"; } else if (e.KeyChar == 44) { this.label1.Text = "Press_回车"; } } } }
在KeyDown和KeyPress 中没有截获 回车,KeyUp中 都截获了