Convert delegate from C # to vb.net

I'm having trouble converting a C # delegate to VB.NET.

How can I do that?

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; }; } 
+4
source share
1 answer

None of these methods use any context in the constructor itself, so I would convert each anonymous method to a β€œregular” method in your VB code (which should be simple), and then use something like this in your constructor

 AddHandler _twain.TransferImage, AddressOf(TransferImageHandler) AddHandler _twain.ScanningComplete, AddressOf(ScanningCompleteHandler) 

Methods must have the same signature as the events that they process.

+4
source

All Articles