I have an application where I would like to create an event system that will pass a custom event argument to a series of form controls.
Essentially, this is meant to be a rudimentary access control mechanism. The custom argument will contain an object that will indicate a requested access level and each control will then take actions based on the values in the passed event argument.
I was looking into defining a custom event (see attached snippet), but I am not quite sure how to wire all this up.
A couple of questions:
1) Is this do-able? Can an entire class be passed as an event argument?
2) Will a disabled control still be able to receive a custom event message?
3) Can all my controls respond to the same custom event at the same time?
4) How do I wire all this up?
I was thinking about deriving control classes from each of the UI control types I will be using so that I can define the custom event handler for each UI control from within the derived control class. I could add the handler when I create an instance of the control and remove it on disposal. Does that make sense?
Public Enum AccessLevels As Integer
Guest ' Read Only access (and non-SSN reports)
Staff ' Team Managers & Staff
Physician ' Area Managers
Administrator ' Administrator
Public Class AccessToken
Private _AccessLevel As AccessLevels
Public Property AccessLevel() As AccessLevels
Set(ByVal value As AccessLevels)
_AccessLevel = value
Public Sub New(ByVal Level As AccessLevels)
AccessLevel = Level
Public Class MyEventArg
Private _Token As AccessToken
Public Property Token() As AccessToken
Set(ByVal value As AccessToken)
_Token = value
Public Custom Event AccessLevelEvent As EventHandler
AddHandler(ByVal d As EventHandler)
RemoveHandler(ByVal d As EventHandler)
RaiseEvent(ByVal sender As Object, ByVal e As MyEventArg)