K
Karl Rhodes
Hi all, I'm in the middle of converting some C# code to VB and I'm
almost done, but this last little bit is confusing me.
I'm trying to convert the following C# code...
public event EventHandler<EnterKeyEventArgs> EnterKeyEvent;
private void Body_KeyDown(object sender, HtmlElementEventArgs e)
{
if (e.KeyPressedCode == 13 && !e.ShiftKeyPressed)
{
// handle enter code cancellation
bool cancel = false;
if (EnterKeyEvent != null)
{
EnterKeyEventArgs args = new EnterKeyEventArgs();
EnterKeyEvent(this, args);
cancel = args.Cancel;
}
e.ReturnValue = !cancel;
}
}
into VB, and so far I have...
Public Event EnterKeyEvent As EventHandler(Of EnterKeyEventArgs)
Private Sub Body_KeyDown(ByVal sender As Object, ByVal e As
HtmlElementEventArgs)
If e.KeyPressedCode = 13 AndAlso Not e.ShiftKeyPressed Then
Dim cancel As Boolean = False
If Not IsNothing(EnterKeyEvent) Then 'PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me, args)
cancel = args.Cancel
End If
e.ReturnValue = Not cancel
End If
End Sub
There is a line in the VB section above with a comment "PROBLEM LINE"
at the end. Visual Studio gives me the following error...
"
'Public Event EnterKeyEvent(sender as Object, e as EnterKeyEventArgs)'
is an event, and cannot be called directly. Use a 'RaiseEvent'
statement to raise an event
"
I thought this was checking for an event and not trying to raise one?
If anyone know's how I should do this I would be most grateful!
Karl
almost done, but this last little bit is confusing me.
I'm trying to convert the following C# code...
public event EventHandler<EnterKeyEventArgs> EnterKeyEvent;
private void Body_KeyDown(object sender, HtmlElementEventArgs e)
{
if (e.KeyPressedCode == 13 && !e.ShiftKeyPressed)
{
// handle enter code cancellation
bool cancel = false;
if (EnterKeyEvent != null)
{
EnterKeyEventArgs args = new EnterKeyEventArgs();
EnterKeyEvent(this, args);
cancel = args.Cancel;
}
e.ReturnValue = !cancel;
}
}
into VB, and so far I have...
Public Event EnterKeyEvent As EventHandler(Of EnterKeyEventArgs)
Private Sub Body_KeyDown(ByVal sender As Object, ByVal e As
HtmlElementEventArgs)
If e.KeyPressedCode = 13 AndAlso Not e.ShiftKeyPressed Then
Dim cancel As Boolean = False
If Not IsNothing(EnterKeyEvent) Then 'PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me, args)
cancel = args.Cancel
End If
e.ReturnValue = Not cancel
End If
End Sub
There is a line in the VB section above with a comment "PROBLEM LINE"
at the end. Visual Studio gives me the following error...
"
'Public Event EnterKeyEvent(sender as Object, e as EnterKeyEventArgs)'
is an event, and cannot be called directly. Use a 'RaiseEvent'
statement to raise an event
"
I thought this was checking for an event and not trying to raise one?
If anyone know's how I should do this I would be most grateful!
Karl