[英]C#- system.eventargs' does not contain a definition for 'graphics'
[英]System.EventArgs Doesn't contain the definition of Button - C#
实际上, DataGridView
的MouseClick
事件提供了一个MouseEventArgs
参数。 您仅使用EventArgs
声明了datagridview1_MouseClick
方法。
更改为
protected void datagridview1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == ...
它应该工作(如果你使用的CellMouseClick
代替MouseClick
,使用DataGridViewCellMouseEventArgs
而不是MouseEventArgs
)。
附带说明:添加“错误”声明的处理程序(例如datagridview1.MouseClick += datagridview1_MouseClick
,不会出现编译错误,因为MouseEventArgs
派生自EventArgs
,因此编译器对该分配没有问题。 当您将e
声明为EventArgs
时,尝试通过e
访问MouseEventArgs
实例的属性时,就会出现问题,因为EventArgs
不知道MouseEventArgs
派生的属性。
PS:请将您的代码作为文本发布到下一个问题。 与图像相比,对我们而言,读取或重复使用该错误再现更好。 在这个形象,我不能看到,如果你使用的MouseClick
或CellMouseClick
事件
您的委托处理程序方法应使用DataGridViewCellMouseEventArgs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.