将委托从 C# 转换为 vb.net
我在将 C# 委托转换为 VB.NET 时遇到问题。
这怎么能做到呢?
public MainForm()
{
InitializeComponent();
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
{
if (args.Image != null)
{
pictureBox1.Image = args.Image;
widthLabel.Text = "Width: " + pictureBox1.Image.Width;
heightLabel.Text = "Height: " + pictureBox1.Image.Height;
}
};
_twain.ScanningComplete += delegate
{
Enabled = true;
};
}
I'm having trouble converting a C# delegate to VB.NET.
How can this be done?
public MainForm()
{
InitializeComponent();
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
{
if (args.Image != null)
{
pictureBox1.Image = args.Image;
widthLabel.Text = "Width: " + pictureBox1.Image.Width;
heightLabel.Text = "Height: " + pictureBox1.Image.Height;
}
};
_twain.ScanningComplete += delegate
{
Enabled = true;
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些方法似乎都没有在构造函数本身中使用任何上下文,因此我会将每个匿名方法转换为 VB 代码中的“正常”方法(这应该很简单),然后在构造函数中使用类似的
方法 :应该与他们正在处理的事件具有相同的签名。
Neither of those methods seem to use any context in the constructor itself, so I would convert each anonymous method into a "normal" method in your VB code (which should be straightforward), and then use something like this in your constructor:
The methods should have the same signature as the events they're handling.