How to use a RaiseEvent statement in Visual Basic 2008?

T

Tom Shelton

Hello. In project Visual Studio 2008, Visual C#, Windows Forms Application,
I have written down such code on C# without errors:

    public class UiButton

    {

        public event EventHandler Click;

        public void OnMouseClick(int x, int y)

        {

            if (Click != null)

                Click(this, EventArgs.Empty);

        }

    }

The same code, I have copied in the project Visual Studio 2008, Visual
Basic, Windows Forms Application  in such kind on Visual Basic:

Public Class UiButton

    Public Event Click As EventHandler

    Public Sub OnMouseClick(ByVal x As Integer, _

    ByVal y As Integer)

        If (RaiseEvent Click <> Nothing) Then

            RaiseEvent Click(Me, EventArgs.Empty)

        End If

    End Sub

End Class

The compiler is emphasized the first RaiseEvent statement and gives out the
message on this error:

Expression expected.

Inform, please, how correctly to write down this code on Visual Basic?

Many thanks, Zharkov, Moskva, Rossiya.

You don't need to test the delegate for nothing in VB.NET the
RaiseEvent statement will do it for you...

Public Class UiButton
Public Event Click As EventHandler
Public Sub OnMouseClick(ByVal x As Integer, _
ByVal y As Integer)

RaiseEvent Click(Me, EventArgs.Empty)
End Sub
End Class

HTH
 
D

Dr. Zharkov

Hello. In project Visual Studio 2008, Visual C#, Windows Forms Application,
I have written down such code on C# without errors:

public class UiButton

{

public event EventHandler Click;



public void OnMouseClick(int x, int y)

{

if (Click != null)

Click(this, EventArgs.Empty);

}

}



The same code, I have copied in the project Visual Studio 2008, Visual
Basic, Windows Forms Application in such kind on Visual Basic:

Public Class UiButton

Public Event Click As EventHandler



Public Sub OnMouseClick(ByVal x As Integer, _

ByVal y As Integer)

If (RaiseEvent Click <> Nothing) Then

RaiseEvent Click(Me, EventArgs.Empty)

End If

End Sub

End Class

The compiler is emphasized the first RaiseEvent statement and gives out the
message on this error:

Expression expected.



Inform, please, how correctly to write down this code on Visual Basic?

Many thanks, Zharkov, Moskva, Rossiya.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top