Introduced
Have you ever tried to integrate a reliable and fast Web browser in your app?
In this article, you'll learn how to easily integrate wonderful Cefsharp Web browser components (chromium-based) into your C # app.
You can then use this web browser:
- Provide an integrated browsing experience to the user
- Adding an embedded interface with Html/javascript programming
- For Web Automation
Cefsharp is reliable, fast, fully open source and can be installed to end users (except VC + + Runtime 2013) without any additional dependencies.
In this guide, we will use the WinForms project, but Cefsharp can also work on a WPF project.
Entry
Follow these steps to quickly start Cefsharp.
Project
1. Create a Windows Forms application (C #) project with. NET 4.5.2
2. Naming the project (e.g. "Ceftest")
DLL file (NuGet method)
3 a) If you are using NuGet, you can grab cefsharp.winforms from the NuGet code warehouse and skip the manual method below.
3B) If you've already used NuGet, navigate solution > Configuration Manager and set your project to x86 or x64 because ANYCPU is not currently supported.
DLL file (manual method)
If you're using NuGet, skip this section!
3 a) Download the Cefsharp binaries and unzip them.
Cefsharp v51 x86 (32-bit app)
Cefsharp V51 x64 (64-bit app)
3B) Right-click on your project, click "Add Reference" and select "Browse".
3C) Select these DLL files:
CefSharp.dll
CefSharp.Core.dll
CefSharp.WinForms.dll
3D) Select all files with Zip:
3 e) Copy those files to the debug folder of the project (in the bin)
Code
4. Right-click on your main form and select "View Code".
5. Add the following code:
Copy to import
section:
Using Cefsharp; using Cefsharp.winforms;
Copy to Code snippet:
public Chromiumwebbrowser Browser; initbrowser() {cef.initialize (new Chromiumwebbrowser (this). Controls.Add (browser); Browser. Dock = DockStyle.Fill;}
InitializeComponent()
call Initbrowser () after the call:
Initbrowser ()
Your code should end up like this:
Run it!
6. Press F5 and you will see the Google homepage!
Troubleshooting
A type of ' System. Io. FileNotFoundException ' Unhandled exception appears in Browser.exe
Additional information: Unable to load file or ' Cefsharp. Core.dll ' assembly or one of its dependencies.
If you receive this error, make sure that you have installed visual C + + redistributable.
A type of ' System. BadImageFormatException ' Unhandled exception appears in Browser.exe
Additional information: Unable to load file or ' Cefsharp. Core, version=43.0.0.0, culture=neutral, assembly
If you get this error, it means you're on a 64-bit PC, and your app is built with AnyCPU mode. You need to change to x86 or x64 mode:
- Open the Solution Explorer panel
- Right-click your project >project Properties
- Click the Build tab
- Change platform target to x86 or x64
Full-featured Browser
If you're looking for a full-featured browser project, check out these open-source browsers built with C # cefsharp.
Webexpress
Wpf. Address bar with suggestions, multiple tags, downloads, bookmarks, history.
< author does not provide >
Sharpbrowser
Windows Forms. Address bar, multi-label, download.
Link: http://www.codeceo.com/article/cefsharp-charp-app-chrome.html
English Original: Embedding Chrome in your C # App using Cefsharp
Embed Chrome in the C # App using Cefsharp