怎么做“WithEvents”在C#? [英] How to do "WithEvents" in C#?

查看:163
本文介绍了怎么做“WithEvents”在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个VB.NET代码的C#等价物是什么:

Private WithEvents IE_Inst As New SHDocVw.InternetExplorer


我得到:

private SHDocVw.InternetExplorer IE_Inst = new SHDocVw.InternetExplorer();


但我不知道如何翻译WithEvents部分。有什么建议吗?


谢谢,

Brett

What is the C# equivalent for this VB.NET code:
Private WithEvents IE_Inst As New SHDocVw.InternetExplorer

I get as far as:
private SHDocVw.InternetExplorer IE_Inst = new SHDocVw.InternetExplorer();

but am not sure how to translate the WithEvents part. Any suggestions?

Thanks,
Brett

推荐答案

>这个VB.NET代码的C#等价物是什么:Private WithEvents
> What is the C# equivalent for this VB.NET code: Private WithEvents
IE_Inst As New SHDocVw.InternetExplorer
IE_Inst As New SHDocVw.InternetExplorer




C#不直接支持WithEvents 。

看看C#和VB.NET之间的区别
http://www.codeproject.com/dotnet/vb...difference.asp


您的问题:

你必须定义每个事件,你要在哪里使用事件处理程序,

明确:


SHDocVw.Event1 + = new EventHandler( HandleEvent_Function1);

SHDocVw.Event2 + = new EventHandler(HandleEvent_Function2);

....

hth

thoean



C# does not support WithEvents directly.
Have a look at differences between C# and VB.NET at
http://www.codeproject.com/dotnet/vb...difference.asp

To your question:
You have to define each event, where you want to use an event handler,
explicitly:

SHDocVw.Event1 += new EventHandler(HandleEvent_Function1);
SHDocVw.Event2 += new EventHandler(HandleEvent_Function2);
....
hth
thoean


''事件''在C#中不是必需的。 (它*不应该在VB中被要求,但是

这是一个不同的故事)。


David Anton
www.tangiblesoftwaresolutions.com

Instant C#VB.NET的主页C#转换器

和Instant VB C#到VB.NET转换器


" Markus Thurner"写道:
''WithEvents'' is not required in C#. (It *shouldn''t* be required in VB, but
that''s a different story).

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter

"Markus Thurner" wrote:
这个VB.NET代码的C#等价物是什么:Private WithEvents
IE_Inst As New SHDocVw.InternetExplorer
What is the C# equivalent for this VB.NET code: Private WithEvents
IE_Inst As New SHDocVw.InternetExplorer



C#不直接支持WithEvents。
了解C#和VB.NET之间的差异
http://www.codeproject.com/dotnet/vb...difference.asp

给你问题:
你必须明确地定义每个事件,你要在哪里使用事件处理程序:

SHDocVw.Event1 + = new EventHandler(HandleEvent_Function1);
SHDocVw.Event2 + = new EventHandler(HandleEvent_Function2);
....

hth
thoean



C# does not support WithEvents directly.
Have a look at differences between C# and VB.NET at
http://www.codeproject.com/dotnet/vb...difference.asp

To your question:
You have to define each event, where you want to use an event handler,
explicitly:

SHDocVw.Event1 += new EventHandler(HandleEvent_Function1);
SHDocVw.Event2 += new EventHandler(HandleEvent_Function2);
....
hth
thoean



别担心。这是VB中关键词腹泻的另一个例子。它好像适用于重载覆盖的白痴。和VB编译器

坚持看到Readonly关键字,即使它可以看到

没有设置访问器。


如果一个类暴露公共事件,那么你可以使用

+ +运算符添加一个处理程序,例如...


theForm.Paint + = new PaintEventHandler (这个painthandler); //这是相当于AddHandler的




您可以删除类似的事件 - =相当于

removehandler。


-

Bob Powell [MVP]

Visual C#,System.Drawing


在Windows窗体中查找精美的Windows窗体提示和技巧
http: //www.bobpowell.net/tipstricks.htm


用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm


全新文章提供了C#和VB.NET中的代码。

订阅提供的RSS提要,绝不会错过任何新文章。


" Brett" < no@spam.com>在消息中写道

news:u
Don''t worry about it. It''s another example of keyword diarrhea in VB. It
fits right in with the idiocy of "overloads overrides" and the VB compilers
insistence on seeing the Readonly keyword even when it can see that there is
no set accessor.

If a class exposes public events then you can add a handler to them using
the += operator such as...

theForm.Paint+=new PaintEventHandler(this painthandler); // This is the
equivalent of AddHandler

you can remove events similarly with -= being the equivalent of
removehandler.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brett" <no@spam.com> wrote in message
news:u


这篇关于怎么做“WithEvents”在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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