It is a bit sad that the compiler doesn't generate an error for this. You have to make it look like this:
Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load
obj1 = New Class1
AddHandler Class2.TestEvent, AddressOf handleEventFromClass2
End Sub
Private Sub handleEventFromClass2(ByRef sender As Class2, _
ByVal op As Integer)
TextBox1.Text = "Wert : " & op
End Sub
Note that missing Handles keyword on the event handler and the explicit use of the AddHandler keyword. You are however going to get yourself into trouble with these Shared events. There is no mechanism that automatically unsubscribes the event, Shared makes it global so it lives for the duration of your program. Even after the user has closed the form. That's going to go bad, an ObjectDisposedException is likely be raised when you fire the event since the form object is dead. Furthermore, you have a permanent leak since the form object can't be garbage collected.
You have to explicitly unsubscribe the event:
Private Sub Form1_FormClosed(ByVal sender As Object, _
ByVal e As FormClosedEventArgs) Handles Me.FormClosed
RemoveHandler Class2.TestEvent, AddressOf handleEventFromClass2
End Sub
Event sources that outlive their listeners are troublesome.
It is just a different coding language, but C is more for business that VBNET
They are different tools for different jobs. Which is better a hammer or a screwdriver?
They use different syntax.
Java is not better than VBNet, nor is VBNet better than Java. Eachone has its advantages and disadvantaged over the other one.
x
An instance in VBNet is the same as an instance in any other language; it is the realisation of a type. In object-oriented languages, like VBNet, we say that an object is an instance of a class, where the class defines the object's type.
An instance in VBNet is the same as an instance in any other language; it is the realisation of a type. In object-oriented languages, like VBNet, we say that an object is an instance of a class, where the class defines the object's type.
no
Alan Cooper
Microsoft Microsoft.com/VisualStudio
NO.
VBnet program to find the prime numbers between 100 to 200?