更新时间:2023-02-16 20:47:46
" Karl Rhodes" < go ********** @ cortexa.co.ukschrieb:
If Not IsNothing(EnterKeyEvent)Then''PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me,args)
cancel = args.Cancel
结束If
只需删除无的检查。如果代表被附加,''RaiseEvent''只会提高
事件,遗憾的是没有在C#中完成。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http:// dotnet.mvps.org/dotnet/faqs/>
8月13日,22:43,Herfried K. Wagner [MVP]" < hirf-spam-me-
h ... @ gmx.atwrote:
" Karl Rhodes" < googlegro ... @ cortexa.co.ukschrieb:
If Not IsNothing(EnterKeyEvent)Then''PROBLEM LINE
Dim args作为New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me,args)
cancel = args.Cancel
结束如果
只需删除没有的检查。如果代表被附加,''RaiseEvent''只会提高
事件,遗憾的是没有在C#中完成。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http:// dotnet.mvps.org/dotnet/faqs/>
嗨Herfried,
我担心它没有任何区别。我把这行改为
两个如果EnterKeyEvent然后和If(EnterKeyEvent)然后我仍然
有同样的错误...
您是否完全删除了if语句?
Karl
" Karl Rhodes" < go ********** @ cortexa.co.ukschrieb:
If Not IsNothing(EnterKeyEvent)然后''问题行
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me,args)
cancel = args.Cancel
结束如果
只需删除没有的检查。如果代表被附加,''RaiseEvent''只会引发
事件,遗憾的是,这不会在C#中完成。
我担心它没有任何区别。我把这行改为
两个如果EnterKeyEvent然后和If(EnterKeyEvent)然后我仍然
有同样的错误...
您是否完全删除了if语句?
是的,VB中根本不需要它。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http:// dotnet。 mvps.org/dotnet/faqs/>
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<EnterKeyEventArgsEnterKeyEvent;
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
"Karl Rhodes" <go**********@cortexa.co.ukschrieb:If Not IsNothing(EnterKeyEvent) Then ''PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me, args)
cancel = args.Cancel
End IfSimply remove the check for ''Nothing''. ''RaiseEvent'' will only raise the
event if delegates are attached, which is unfortunately not done in C#.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
On 13 Aug, 22:43, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:"Karl Rhodes" <googlegro...@cortexa.co.ukschrieb:If Not IsNothing(EnterKeyEvent) Then ''PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me, args)
cancel = args.Cancel
End If
Simply remove the check for ''Nothing''. ''RaiseEvent'' will only raise the
event if delegates are attached, which is unfortunately not done in C#.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>Hi Herfried,
I''m afraid it hasn''t made any difference. I changed the line to read
both "If EnterKeyEvent Then" and "If (EnterKeyEvent) Then" and I still
have the same error...
Did you mean for me to remove the if statement altogether?
Karl
"Karl Rhodes" <go**********@cortexa.co.ukschrieb:If Not IsNothing(EnterKeyEvent) Then ''PROBLEM LINE
Dim args As New EnterKeyEventArgs()
RaiseEvent EnterKeyEvent(Me, args)
cancel = args.Cancel
End If
Simply remove the check for ''Nothing''. ''RaiseEvent'' will only raise the
event if delegates are attached, which is unfortunately not done in C#.
I''m afraid it hasn''t made any difference. I changed the line to read
both "If EnterKeyEvent Then" and "If (EnterKeyEvent) Then" and I still
have the same error...
Did you mean for me to remove the if statement altogether?Yes, it''s not required at all in VB.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>