Embed Chrome in the C # App using Cefsharp

Source: Internet
Author: User
Tags fast web

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:

    1. Open the Solution Explorer panel
    2. Right-click your project >project Properties
    3. Click the Build tab
    4. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.