Hi faizanak,
To replace the .NET WebBrowser control with a better browser like Chrome in your .NET application, you can use a third-party browser control that is based on the Chromium engine, such as CefSharp.
You need to Install the CefSharp NuGet package: ChromiumWebBrowser is usually provided through the CefSharp library. You can install it via NuGet Package Manager in Visual Studio.
Replace WebBrowser references: Locate all instances where you've used the WebBrowser control in your code and replace them with ChromiumWebBrowser.
Import necessary namespaces: Make sure to import the appropriate namespaces for ChromiumWebBrowser. This typically includes CefSharp.WinForms or CefSharp.Wpf depending on whether you're using WinForms or WPF.
Initialization Unlike WebBrowser, ChromiumWebBrowser requires explicit initialization. Ensure you initialize the ChromiumWebBrowser instance in your code, typically in your form's constructor or Load event handler.
Configuration Depending on your needs, you might want to configure settings for ChromiumWebBrowser, such as cache size, proxy settings, etc. This is usually done during initialization.
Below is the working code.
You will need to add the CefSharp.WinForms package from Nuget.
Form
Namespaces
C#
using CefSharp;
using CefSharp.WinForms;
VB.Net
Imports CefSharp
Imports CefSharp.WinForms
C#
public Form1()
{
InitializeComponent();
InitBrowser();
}
public ChromiumWebBrowser browser;
public void InitBrowser()
{
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("www.aspsnippets.com");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
VB.Net
Public Sub New()
InitializeComponent()
InitBrowser()
End Sub
Public browser As ChromiumWebBrowser
Public Sub InitBrowser()
Cef.Initialize(New CefSettings())
browser = New ChromiumWebBrowser("www.aspsnippets.com")
Me.Controls.Add(browser)
browser.Dock = DockStyle.Fill
End Sub
Screenshot