使用继承形式的事件 [英] Using events in a inherited form

查看:84
本文介绍了使用继承形式的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个我继承的基本表单。该基地有一个自定义的

事件。该事件不会引发抛弃继承的形式。我想知道

如果事件的工作是继承还是我应该使用其他方法?


-

Chad Miller

软件开发总裁兼总监

Predictive Concepts,Inc。
www.predictiveconcepts.com

407.327.9910

解决方案

它似乎工作对我来说很好(VS2003,.net 1.1)。


你能发一个简短的代码示例吗?


如果你使用VB,派生形式中事件处理程序的示例

将是:


------------------ -----

Private Sub MyEventHandler(ByVal sender As Object,ByVal e As

System.EventArgs)处理MyBase.MyEvent

调试.WriteLine(" Bla!")

End Sub

----------------------


" Chad Miller" < CH ** @ predictiveconcepts.com>在消息中写道

新闻:Gd ****************** @ twister.tampabay.rr.com。 ..

我目前有一个我继承的基本表格。基地有一个定制的
事件。该事件不会引发抛弃继承的形式。我想知道
是否有事件可以继承或者我应该使用其他方法吗?

-
Chad Miller
软件开发总裁兼总监
Predictive Concepts,Inc。
www.predictiveconcepts.com
407.327。 9910



*" Chad Miller" < CH ** @ predictiveconcepts.com> scripsit:

我目前有一个我继承的基本表格。基地有一个定制的
事件。该事件不会引发抛弃继承的形式。我想知道
如果事件的工作是继承还是我应该使用其他方法?




您是否正在捕获基类的事件?或者你想在基类中引发一个

事件?

要在基类中引发一个事件,定义一个受保护的方法

''On< EventName>'',它要求事件处理程序的参数为

参数。此方法引发基类中定义的事件。可以通过派生类调用

方法来提升基类''

事件。活动不是继承的!


-

Herfried K. Wagner [MVP]

< http:// www。 mvps.org/dotnet>


>事件不是继承的!


不正确。事件*是*继承的,但派生类不能引发基类中定义的

事件。


Trev。


" Herfried K. Wagner [MVP]" <喜*************** @ gmx.at>在消息中写道

news:uc **************** @ TK2MSFTNGP09.phx.gbl ...

*" Chad Miller < CH ** @ predictiveconcepts.com> scripsit:

我目前有一个我继承的基本表格。基地有一个定制的
事件。该事件不会引发抛弃继承的形式。我是
想知道事件是否有效继承或者我应该使用其他方法吗?



你是否正在捕获基类的事件?或者你想在基类中引发一个
事件?

要在基类中引发一个事件,定义一个受保护的方法
''On< EventName>''期望事件处理程序的参数为
参数。此方法引发基类中定义的事件。
方法可以由派生类调用以引发基类''
事件。事件不是继承的!

- Herfried K. Wagner [MVP]
< http://www.mvps.org/dotnet>



I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was wondering
if events work threw inheritance or should I use some other method?

--
Chad Miller
President and Director of Software Development
Predictive Concepts, Inc.
www.predictiveconcepts.com
407.327.9910

解决方案

It seems to work fine for me (VS2003, .net 1.1).

Could you post a short code example?

If you are using VB, an example of the event handler in the derived form
would be:

-----------------------
Private Sub MyEventHandler(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MyEvent
Debug.WriteLine("Bla!")
End Sub
----------------------

"Chad Miller" <ch**@predictiveconcepts.com> wrote in message
news:Gd******************@twister.tampabay.rr.com. ..

I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was wondering
if events work threw inheritance or should I use some other method?

--
Chad Miller
President and Director of Software Development
Predictive Concepts, Inc.
www.predictiveconcepts.com
407.327.9910



* "Chad Miller" <ch**@predictiveconcepts.com> scripsit:

I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was wondering
if events work threw inheritance or should I use some other method?



Are you catching an event of the base class? Or do you want to raise an
event in the base class?

To raise an event in the base class, define a protected method
''On<EventName>'' which expects the parameters of the event handler as
arguments. This method raises the event defined in the base class. The
method can be called by a derived class to raise the base class''
event. Events are not inherited!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


> Events are not inherited!

Not correct. Events *are* inherited, but a derived class cannot raise an
event defined in a base class.

Trev.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uc****************@TK2MSFTNGP09.phx.gbl...

* "Chad Miller" <ch**@predictiveconcepts.com> scripsit:

I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was wondering if events work threw inheritance or should I use some other method?



Are you catching an event of the base class? Or do you want to raise an
event in the base class?

To raise an event in the base class, define a protected method
''On<EventName>'' which expects the parameters of the event handler as
arguments. This method raises the event defined in the base class. The
method can be called by a derived class to raise the base class''
event. Events are not inherited!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>



这篇关于使用继承形式的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆