In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use CefSharp to embed Chrome browser in C # App. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Introduction
Have you ever tried to integrate a reliable and fast web browser into app?
How to easily integrate the wonderful CefSharp web browser components (based on Chromium) into your C # app.
You can then use this web browser:
Provide users with an integrated browsing experience
Adding embedded Interface with HTML / JavaScript programming
For web automation
CefSharp is reliable, fast, completely open source, and can be installed to end users (except VC + + Runtime 2013) without any additional dependencies.
We will use the WinForms project, but CefSharp can also work on the WPF project.
Introduction
Follow these steps to start CefSharp quickly.
Project
1. Create a Windows forms application (C #) project with .NET 4.5.2
two。 Name the project (such as "CefTest")
DLL file (NuGet method)
3A) if you are using NuGet, you can grab CefSharp.WinForms from the NuGet code repository and skip the manual method below.
3B) if you are already using NuGet, navigate SOLUTION > Configuration Manager and set your project to x86 or x64, because AnyCPU is not currently supported.
DLL files (manual method)
If you are using NuGet, please skip this chapter!
3A) download the CefSharp binaries and extract them.
CefSharp v51 x86 (32-bit app)
CefSharp v51 x64 (64-bit app)
3B) right-click your project, click "Add Reference", and then select "Browse".
3C) Select these DLL files:
CefSharp.dll
CefSharp.Core.dll
CefSharp.WinForms.dll
3D) use ZIP to select all files:
3e) copy those files to the Debug folder of the project (in Bin)
Code
4. Right-click your main form and select "View Code".
5. Add the following code:
Copy to the import section:
Using CefSharp;using CefSharp.WinForms
Copy to code snippet:
Public ChromiumWebBrowser browser;public void InitBrowser () {Cef.Initialize (new CefSettings ()); browser = new ChromiumWebBrowser ("www.google.com"); this.Controls.Add (browser); browser.Dock = DockStyle.Fill;}
After calling InitializeComponent (), call InitBrowser ():
InitBrowser ()
Your code should end up like this:
Run it!
6. Press the F5 key and you will see the Google home page!
Troubleshooting
An unhandled exception of type 'System.IO.FileNotFoundException' 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 you have Visual C + + 2013 Redistributable installed.
An unhandled exception of type 'System.BadImageFormatException' appears in browser.exe
Other information: unable to load file or 'CefSharp.Core, Version=43.0.0.0, Culture=neutral, assembly
If you get this error, it means that you are on 64-bit PC and your app is built in 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-function browser
If you are 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, and history.
SharpBrowser
Windows Forms . Address bar, multiple tags, download.
The above is how to use CefSharp to embed Chrome browser in C # App. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.