![](/img/trans.png)
[英]How to use event handler with delegate from child class with interface
[英]How to access the event handler from the class to use in the Form
我有一个继承自DataGridView的类,并且有一个与下面的代码相同的EventArgs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyTest
{
class Test1:System.Windows.Forms.DataGridView
{
private void Test1_Click(object sender, EventArgs e)
{
MessageBox.Show("Click");
}
}
}
然后,我有一个表单,我想在表单中使用Test1。 所以我将Test1从Toolbox拖到窗体上。我想要的是,当我运行窗体并单击Test1时,它将显示消息“ CellMousClick”,但是当我运行窗体时,它不显示任何内容。
在Test1类中创建一个构造函数,并附加一个事件处理程序,例如:
public Test1()
{
this.CellMouseClick += new DataGridViewCellMouseEventHandler(this.Test1_Click);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.