关于事件的问题!!
在用户控件里是这样写的:
public delegate void TextBoxKeyDown(object sender, EventArgs e);
[Description("在首次按下某个键时发生]")]
public event TextBoxKeyDown ControlTextbox_KeyDown;
private void TextBox_txt_KeyDown(object sender, KeyEventArgs e)
{
if (this.ControlTextbox_KeyDown != null) ControlTextbox_KeyDown(sender, e);
}
在窗体中是这样写的
private void controlTextBox_Supplier_ControlTextbox_KeyDown(object sender, EventArgs e)
{
try
{
if (e.KeyValue == 13)
{
MessageBox.Show("测试");
}
}
catch (Exception ex)
{
Common_MessageBox.ShowError(ex.Message);
}
}
错误提示:“System.EventArgs”不包含“KeyValue”的定义,并且找不到可接受类型为“System.EventArgs”的第一个参数的扩展方法“KeyValue”(是否缺少 using 指令或程序集引用?)
------解决方案--------------------
public delegate void TextBoxKeyDown(object sender, EventArgs e);
==>
public delegate void TextBoxKeyDown(object sender, KeyEventArgs e);