Razor89 Posted December 25, 2004 Posted December 25, 2004 I don't know if this should have gone in the general area or what but since I use VB.NET and I have no clue if C# supports events and all that stuff I will ask my question here. Now for my question. I have seen some events in my coding experience that have the following parameters for example: Public Event MyEvent(Byval Cancel As Boolean) Handles Whatever.MyEvent Now in events like these if you set Cancel to TRUE, whatever should happen after the event is raised will stop. How do I do this in my own classes? I tried playing with ByRef and all that stuff to pass a variable from inside my sub that raises the event and then checking the value of that variable after the event has been raised, but no luck. Thanks for any input! Quote
*Experts* mutant Posted December 26, 2004 *Experts* Posted December 26, 2004 (edited) The best way to do this would be to create your own arguments object and expose a boolean property (my example uses a public variable for the sake of simplicity). Here is the example: Public Class Class1 Public Event Hello(ByVal cancel As ARGS) Public Sub RaiseTheEvent() Dim res As New ARGS RaiseEvent Hello(res) 'The message will now show the value of cancel that is there, it will be different 'if you changed it in the event handler MessageBox.Show(res.cancel.ToString()) 'of course you can do anything you want with that value, i just used the MBox 'as an example End Sub End Class Public Class ARGS Public cancel As Boolean = False End Class Edited December 26, 2004 by mutant Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.