Sometimes, we need to embed a Web browser in the program, in fact, the. Net framework itself provides the WebBrowser control, itself this is the most simple and easy-to-use solution, but do not know what the reason, this control when browsing the web, some inexplicable lag, Sometimes it can even reach several seconds, seriously affecting the experience.
At this time, we can consider using a third-party browser instead of the system's WebBrowser, the common scenario is to use the version of the Chrome,chrome itself provides a program for third-party programs embedded in the Chromium Embedded Framework (CEF), But this is the interface of C + +, and there is a certain amount of work to be used in. NET programs. However, there are already some open source projects to complete this package, one of the best is the CEFSHARP,WPF and WinForm package is implemented, this article briefly describes how to use the Cefsharp in a WPF program to embed Chrome browser.
Installation:
The installation process is simple, as long as you install CEFSHARP.WPF with NuGet.
???? Pm> Install-package CEFSHARP.WPF
The installation process itself is relatively routine, but it is worth mentioning that this package is very large, due to the integration of the x86 and x64 versions, the entire package (plus a few dependent packages) reached more than 200 MB, based on well-known reasons, and NuGet access has been not smooth, and sometimes the whole process of convulsions is very long, Be patient and character.
?
To modify the compilation options:
Because Chrome is a native program, currently CEFSHARP is not able to do 32-bit and 64-bit automatic recognition, cannot use the default ANYCPU compilation options, need to modify the Configuration Manager, change to x86 or x64.
?
Use:
The use of the process is relatively simple, directly using the following code.
????PrivatevoidMainwindow_loaded (ObjectSenderRoutedEventArgsE
???? {
????????Var setting = new Cefsharp.cefsettings ();
???????? Cefsharp. ceftruefalse
???????? var WebView = new CEFSHARP.WPF. chromiumwebbrowser???????? this
???????? webview.address = "http://www.cnblogs.com/TianFang/" ????}
This article is just a brief introduction of the basic usage of cefsharp, the next article in the next introduction more about how to do more in-depth customization, on the CEFSHARP website itself has a more detailed example, interested friends can study.
?
Embed a Chrome browser in a. NET program using Cefsharp (a)--introduction