将C#转换为VB时出错 [英] Error converting c# to vb

查看:127
本文介绍了将C#转换为VB时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

将C#代码转换为vb时,我在转换一行代码时遇到问题.
C#代码为

Hello ALL,

While converting a c# code to vb i am facing a problem in converting a line of code.
The c# code is

private void Button_Loaded(object sender, RoutedEventArgs e)
{
    ((Button)sender).AddHandler(Button.MouseLeftButtonDownEvent,
        new MouseButtonEventHandler(Button_MouseLeftButtonDown), true);
    ((Button)sender).AddHandler(Button.MouseLeftButtonUpEvent,
        new MouseButtonEventHandler(Button_MouseLeftButtonUp), true);

    ((Button)sender).MouseMove += new MouseEventHandler(Button_MouseMove);
}



虽然我能够获取Button.MouseLeftButtonDownEvent和Button.MouseLeftButtonUpEvent事件,但我却无法获取MouseMove事件,
转换后的代码就是这样..



while i am able to get the Button.MouseLeftButtonDownEvent and Button.MouseLeftButtonUpEvent events i am not able to get the MouseMove event,
the converted code is something like this..

Private Sub Button_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
       DirectCast(sender, Button).AddHandler(Button.MouseLeftButtonDownEvent, New MouseButtonEventHandler(AddressOf Button_MouseLeftButtonDown), True)
       DirectCast(sender, Button).AddHandler(Button.MouseLeftButtonUpEvent, New MouseButtonEventHandler(AddressOf Button_MouseLeftButtonUp), True)

       DirectCast(sender, Button).MouseMove += New MouseEventHandler(AddressOf Button_MouseMove) 
End Sub



但是DirectCast(sender,Button).MouseMove不起作用,它引发了一个错误,指出
MouseMove是一个事件,不能直接使用Raiseevent引发该事件.

这里有什么问题?以及我该如何解决?

期待您的回答...
预先感谢.



But the DirectCast(sender,Button).MouseMove does not work it throws an error stating
MouseMove is an event and cannot be called directly use an Raiseevent to raise the event.

What is the problem here? and how can i fix this?

Looking forward to your answer...
Thanks in advance.

推荐答案

我可以清楚地看到MouseMove行与其他两条行之间的区别...
您无需在VB中使用+ =运算符来添加事件处理程序.
I can clearly see the difference between the MouseMove line and the other two...
You don''t use the += operator in VB to add an event handler.


这篇关于将C#转换为VB时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆