简体   繁体   English

将代码c#转换为vb.net委托

[英]convert code c# to vb.net delegate

I'm trying to convert the c # code of a sample code to vb.net but I could with the following line of code. 我正在尝试将示例代码的c#代码转换为vb.net,但我可以使用以下代码行。 it is an event, delegate. 这是一个事件,代表。 but I can not build a functional structure. 但我无法建立一个功能结构。 someone could help me? 有人可以帮帮我吗? thanks 谢谢

Ellipse node = new Ellipse();
node.Style = nodeStyle;

node.MouseEnter += delegate(object sender, MouseEventArgs e) {
    if (selectedNode == null)
        node.BeginStoryboard((Storyboard)FindResource("NodeFadeIn"));
};

node.MouseLeave += delegate(object sender, MouseEventArgs e) {
    if (selectedNode == null)
        node.BeginStoryboard((Storyboard)FindResource("NodeFadeOut"));
};

node.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) {
    e.Handled = true;
    selectedNode = (Ellipse)sender;
};

You need to use the AddHandler keyword in VB.NET to subscribe event handlers. 您需要在VB.NET中使用AddHandler关键字来订阅事件处理程序。 In VS2010, an anonymous method can be substituted with a lambda, like this: 在VS2010中,匿名方法可以用lambda替换,如下所示:

    AddHandler node.MouseEnter, _
        Sub()
            If node Is Nothing Then
                node.BeginStoryboard(DirectCast(FindResource("NodeFadeIn"), System.Windows.Media.Animation.Storyboard))
            End If
        End Sub

In VS2008 and earlier you'll need to write a little private method. 在VS2008及更早版本中,您需要编写一些私有方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM