Very simple case.
A Form Class inside a Button that triggers a MsgBox
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("TEST")
End Sub
End Class
then I create a new class Class1 and move the Sub Button1_Click to that class
Public Class Form1
End Class
Public Class Class1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Form1.Button1.Click
MessageBox.Show("TEST")
End Sub
End Class
And I get a Failure
Failure BC30506 Handles clause requires a WithEvents variable that is defined in the containing type or one of its base types.
then I modified like this:
Public Class Class1
Public WithEvents Form1.Button As EventThrower()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Form1.Button1.Click
MessageBox.Show("TEST")
End Sub
End Class
And now I get 2 Failures
Error BC30412 ' WithEvents ' variables must have an as clause.
Error BC31412 'Handles' in classes must specify a WithEvents variable, 'MyBase', 'MyClass' or 'Me' qualified with a single identifier.
Can Somebody explain me this in a simple way ?
UPDATE 1:
The Solution coming from Visual Vincent removes the Error but by clicking the Button1 on Form1 the MessageBox gets not fired, so practically its not working.
Public Class Class1
Public WithEvents Button1 As Button = Form1.Button1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("TEST")
End Sub
End Class
How can I get the Button1 on Form1 fired from within the Class1 ?