我在将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; }; }最满意答案
这些方法似乎都没有在构造函数本身中使用任何上下文,所以我将每个匿名方法转换为VB代码中的“普通”方法(应该是直截了当的),然后在构造函数中使用这样的方法:
AddHandler _twain.TransferImage, AddressOf(TransferImageHandler) AddHandler _twain.ScanningComplete, AddressOf(ScanningCompleteHandler)这些方法应该与他们正在处理的事件具有相同的签名。
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:
AddHandler _twain.TransferImage, AddressOf(TransferImageHandler) AddHandler _twain.ScanningComplete, AddressOf(ScanningCompleteHandler)The methods should have the same signature as the events they're handling.
更多推荐
delegate,_twain,NET,VB,Image,电脑培训,计算机培训,IT培训"/> <meta name="
发布评论