Re: How to do "WithEvents" in C#?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Some of the online examples I've seen for events in C# make use of
delegates. No one in this thread has used delegates. Why not?

Here are a few examples that use delegates:
http://www.c-sharpcorner.com/Code/2002/Mar/EventHandlingInNetUsingCSDD001.asp

http://www.codeproject.com/csharp/csevents01.asp

Brett


"Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uiyOGp5TFHA.3392@xxxxxxxxxxxxxxxxxxxxxxx
The .Paint part was just an example of a well-known event.

In your particular case you can declare the object and add the handler like
so:

AxSHDocVw.AxWebBrowser axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
this.axWebBrowser1.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.axWebBrowser1_DocumentComplete);

--
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@xxxxxxxx> wrote in message
news:OQP$MT0TFHA.2812@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:%23AnUlF0TFHA.2520@xxxxxxxxxxxxxxxxxxxxxxx
>> 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
>
> Using my code, what is the .Paint part? Would that be InternetExplorer?
>
> I'm not quite sure how to build the following in C#:
> [VB.NET]
> Private WithEvents IE_Inst As New SHDocVw.InternetExplorer
>
> Maps to things such as:
> Public Sub IEDocComplete(ByVal pDisp As Object, ByRef URL As Object)
> Handles
> IE_Inst.DocumentComplete
>
> Brett
>
>

.



Relevant Pages

  • How do you kill an Asynchronous Delegates thread
    ... I have read several articles about using Asynchronous Delegates and I've ... called whenever BeginInvoke() is called. ... calling EndInvoke() will cause the calling thread to hang, ...
    (microsoft.public.dotnet.framework)
  • Events under C# and .NET
    ... On the topic of delegates, here are just a few articles: ... >Could someone recommend an indepth bookor set of ... subscription. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delegates are useful, and here is why (sample program)
    ... Being inconsistent and ignoring well- ... established conventions *is* distracting, ... delegate can be invoked to traverse the delegates in its chain ... lambda expressions you might want to look at these articles: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to do "WithEvents" in C#?
    ... It's another example of keyword diarrhea in VB. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... > Private WithEvents IE_Inst As New SHDocVw.InternetExplorer ...
    (microsoft.public.dotnet.languages.csharp)