代码转换

本文关键字:转换 代码 | 更新日期: 2023-09-27 18:30:55

我从MSDN那里得到了这段代码。它是用C#编写的,在将其转换为VB窗口表单时遇到问题。

任何人都可以帮助链接

问题在

foreach (Control control in flowLayoutPanel1.Controls)
{
    control.MouseDown += MyMouseDown;
}

代码转换

C# foreach 是 VB For Each

C# Control control是 VB ctrl As Control此处 ctrl,因为 VB 不区分大小写

C# control.MouseDown += MyMouseDown是 VB AddHandler ctrl.MouseDown, AddressOf(MyMouseDown)

另请参阅:AddressOf Operator、AddHandler 语句

所以总而言之:

For Each ctrl As Control In flowLayoutPanel1.Controls
    AddHandler ctrl.MouseDown, AddressOf MyMouseDown
Next

这是你的朋友伴侣:)转换得很好

http://www.developerfusion.com/tools/convert/csharp-to-vb/

使用该站点会将代码转换为:

For Each control As Control In flowLayoutPanel1.Controls
    control.MouseDown += MyMouseDown
Next