将委托从 C# 转换为 vb.net

发布于 2024-11-27 17:56:20 字数 664 浏览 1 评论 0原文

我在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Hello爱情风 2024-12-04 17:56:20

这些方法似乎都没有在构造函数本身中使用任何上下文,因此我会将每个匿名方法转换为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文