-1

I'm trying to incorporate a WebView2 control in a WinForm application. This application, uses a web browser in multiple pages (tabs, dialog forms) and then I have created a custom control (named WebViewCtrl in my sample code) to incorporate the WebView2 control together with some buttons (address text, go next, go previous and refresh). Until I added the custom control to the main window, all seemed to work fine. When I put the control in a modal dialog window, when I need to close the dialog (named TestDialog) the webView2 control loses is father remaining suspended in the screen.

You can check this behaviour in a very simple working sample that I have loaded in github with the essential code to reproduce the issue:

https://github.com/LeonardoDaga/WebView2-Dialog-Sample

I don't understand if I need to do something to kill the control before I dispose the dialog form. Please help if you have any suggestion.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Leonardo Daga
  • 135
  • 1
  • 12

1 Answers1

1

I downloaded your code and found out that you have to Dispose your UserControl when you close your dialog.

In the TestDialog form, add the following event handler to the Form Closed event:

private void TestDialog_FormClosed(object sender, FormClosedEventArgs e)
{
    this.userControl11.Dispose();
}

Now the WebView2 will vanish, when you close the dialog.

Poul Bak
  • 10,450
  • 5
  • 32
  • 57