0

I need to open a webpage and after I press the log in button, a new edge window is being opened. I want to prevent it and I find a lot of questions like this one and converting the code in vb.net I'm getting something like

Imports Microsoft.Web.WebView2.Core
Imports Microsoft.Web.WebView2.WinForms
Public Class Form1

    Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MyBase.OnLoad(e)
        WebView21.CoreWebView2InitializationCompleted += AddressOf OnCoreWebView2InitializationCompleted
        Dim env = Await CoreWebView2Environment.CreateAsync(Nothing, Nothing, Nothing)
        Await WebView21.EnsureCoreWebView2Async(env)
        WebView21.Source = New Uri("https://www.somesite.com")
    End Sub
    Private Sub OnCoreWebView2InitializationCompleted(ByVal sender As Object, ByVal e As CoreWebView2InitializationCompletedEventArgs)
        WebView21.CoreWebView2.NewWindowRequested += AddressOf OnNewWindowRequested
    End Sub

    Private Sub OnNewWindowRequested(ByVal sender As Object, ByVal e As CoreWebView2NewWindowRequestedEventArgs)
        e.Handled = True
        (CType(sender, CoreWebView2)).Navigate(e.Uri)
    End Sub
End Class

but Im getting errors, maybe due to the conversion ( Im using a c# to vb.net online tool)

Description Syntax error.

'Public Event NewWindowRequested As EventHandler(Of CoreWebView2NewWindowRequestedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

'Public Event CoreWebView2InitializationCompleted As EventHandler(Of CoreWebView2InitializationCompletedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

I've also tried this question's answer and I am not getting any error, but in the moment I click in the login button, no new page is being opened or loaded. Is there a fix to it? Thanks

Mattia
  • 258
  • 7
  • 25

0 Answers0