|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Event handlersDoes anyone know if there is a way to check if an event is handled?
Example code: If EventIsHandled then 'Is this possible? RaiseEvent MyEvent(Me, New System.EventArgs) Else 'Do something else ... End If Theo Verweij wrote:
> Does anyone know if there is a way to check if an event is handled? An event handler is the result of having raised an event. That's where > > Example code: > > If EventIsHandled then 'Is this possible? > RaiseEvent MyEvent(Me, New System.EventArgs) > Else > 'Do something else ... > End If you put the code to execute, in the body of the event handler. Why would you want to raise some other event if an event is raised? And if the event is not raised, won't your application just proceed as normal? T Yes, I know how it works.
But what I try to do is give the user of the component the possibility to take some actions, like formating or translating some strings by implementing/handling an event. When the user of this component chooses not to implement this, I want the component to fall back to a default formatting. An example: If EventIsHandled(MyEvent) then 'just made up some syntax RaiseEvent MyEvent(Me, New MyFormattingEventArgs(aStringToFormat)) Else 'Do the standard formatting End If And, by typing this, I found the solution. I just have to put the value of Nothing into the FormattedResult of MyFormattingEventArgs. If it is still Nothing after RaiseEvent, the event was not handled, so I can do the standard formatting. Thanks for your input! tomb wrote: Show quoteHide quote > Theo Verweij wrote: > >> Does anyone know if there is a way to check if an event is handled? >> >> Example code: >> >> If EventIsHandled then 'Is this possible? >> RaiseEvent MyEvent(Me, New System.EventArgs) >> Else >> 'Do something else ... >> End If > > An event handler is the result of having raised an event. That's where > you put the code to execute, in the body of the event handler. > Why would you want to raise some other event if an event is raised? And > if the event is not raised, won't your application just proceed as normal? > > T You need to use the hidden (nearly undocumented) <event>Event variable:
If MyEventEvent Then RaiseEvent MyEvent(Me, New System.EventArgs) Else 'Do something else ... End If -- Show quoteHide quoteDavid Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter C# Code Metrics: Quick metrics for C# "Theo Verweij" wrote: > Does anyone know if there is a way to check if an event is handled? > > Example code: > > If EventIsHandled then 'Is this possible? > RaiseEvent MyEvent(Me, New System.EventArgs) > Else > 'Do something else ... > End If > "David Anton" <DavidAn***@discussions.microsoft.com> schrieb: ACK, but the test is not even necessary because it's already being performed > You need to use the hidden (nearly undocumented) <event>Event variable: > > If MyEventEvent Then > RaiseEvent MyEvent(Me, New System.EventArgs) > Else > 'Do something else ... > End If by 'RaiseEvent'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Personally, I don't do this, but I've come across a lot of code where the
hidden Event variable is checked to ensure that if it is null/Nothing, some other branch of code is executed (even though the RaiseEvent checks for it anyway). Btw, my earlier post should have had: If Not MyEventEvent Is Nothing Then RaiseEvent MyEvent(Me, New System.EventArgs) Else 'Do something else ... End If -- Show quoteHide quoteDavid Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter C# Code Metrics: Quick metrics for C# "Herfried K. Wagner [MVP]" wrote: > "David Anton" <DavidAn***@discussions.microsoft.com> schrieb: > > You need to use the hidden (nearly undocumented) <event>Event variable: > > > > If MyEventEvent Then > > RaiseEvent MyEvent(Me, New System.EventArgs) > > Else > > 'Do something else ... > > End If > > ACK, but the test is not even necessary because it's already being performed > by 'RaiseEvent'. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > > Thank you very much!
David Anton wrote: Show quoteHide quote > Personally, I don't do this, but I've come across a lot of code where the > hidden Event variable is checked to ensure that if it is null/Nothing, some > other branch of code is executed (even though the RaiseEvent checks for it > anyway). > Btw, my earlier post should have had: > If Not MyEventEvent Is Nothing Then > RaiseEvent MyEvent(Me, New System.EventArgs) > Else > 'Do something else ... > End If
Can a .NET Web Service be accessed from a VB6 Client?
Is there a statement that will completely empty a listbox? Threading Question How to code image path relative to project Reporting options in vb 2005 Application Priority Debug Windows Services is My.Settings version specific? DataGrid Row Labeling Update xml file with datagrid on client machine |
|||||||||||||||||||||||