从MouseEventArgs派生的类 [英] class derived from MouseEventArgs
问题描述
我需要一个带有鼠标信息的EventArgs类,但是,当我从MouseEventArgs派生它时,即使我放置了所有权限参数,构造函数也总是存在错误.有办法解决这个问题吗?
谢谢
Hi,
I need an EventArgs class with mouse information but, when i derive it from MouseEventArgs, there is always an error with the constructor, even when i put all the rights arguments. Is there a way to go around this?
Thanks
推荐答案
正确的语法是:
The right syntax is:
public class MyOwnMouseEventArgsWhoKnowsWhy : System.Windows.Forms.MouseEventArgs {
internal MyOwnMouseEventArgsWhoKnowsWhy(
System.Windows.Forms.MouseButtons button,
int clicks,
int x,
int y,
int delta) : base(button, clicks, x, y, delta) {}
} //class MyOwnMouseEventArgsWhoKnowsWhy
我也不知道为什么你会需要它.
在提出问题时,我不会引起您的注意-请参阅我对问题的评论.您甚至没有提到这是编译错误.不是吗?
I have no idea why would you need it though.
I won''t to bring to your attention you problem in formulating questions — please see my comment to the question. You did not even mention that this is a compilation error. Is it not?
根据MSDN,EventArgs类不包含事件数据;引发事件时,不会将状态信息传递给事件处理程序的事件使用它.如果事件处理程序需要状态信息,则应用程序必须从此类派生一个类来保存数据.
如果要创建自己的单击,也可以自己实例化MouseEventArgs:
According to MSDN, EventArgs class contains no event data; it is used by events that do not pass state information to an event handler when an event is raised. If the event handler requires state information, the application must derive a class from this class to hold the data.
If you want to create your own clicks you can just instantiate the MouseEventArgs on your own, too:
MouseEventArgs m = new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 1, 42, 42, 1);
请在 http://msdn.microsoft.com/en-us/library/system上参考MSDN链接. eventargs.aspx [ ^ ]
Refer MSDN link at http://msdn.microsoft.com/en-us/library/system.eventargs.aspx[^]
这篇关于从MouseEventArgs派生的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!