Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

raising .net events from another class?

can I call shared events contained in one class from another class?

for example:

logonclass.vb : handles login logic and authenticates against database

logonmanager.vb: hold current user reference and some logon and timeout events

Logon.vb: A form with a submit button.

I would like to do something like this but I can't get the compiler to agree with it

If VerifyEntries() Then
        Try
            privLvl = LoginClass.AttemptLogin(txtUserName.Text, txtPassword.Text)
        Catch
        End Try
        If privLvl > 0 Then
            'RaiseEvent LoginClass.UserLoggedIn()
            'RaiseEvent LoginManager.UIdisplaychange(privLvl)
            Me.Close()
        End If

    End If

If this isn't the proper way to wire things together let me know so I can learn to structure differently. In my planning it seemed like I was raising a lot of extra duplicate events from my logonclass to my loginmanager class. Then the loginmanager had to raise it again for the main form to see the change event. It got me thinking that if I publicly shared the events and could raise them from wherever then it would cut down on the amount of events I needed in code and the amount of them flying around at runtime.

like image 636
TWood Avatar asked Dec 09 '22 06:12

TWood


1 Answers

In C# the "event" keyword generates a private delegate member object. So it can be accessed only for the class where is defined. But you can expose a public method that will fire the event, and this method can be accessed from outside. I think that in VB is the same.

like image 149
Nicolae Dascalu Avatar answered Dec 23 '22 14:12

Nicolae Dascalu