Embedded Webbroswer in WinForm

Source: Internet
Author: User

This article is original.

The first two days at work need to be embedded in the WinForm form of a browser, we all know that WinForm actually comes with the Webbroswer control, but this control is IE browser, there is such a compatibility problem, not fully meet the needs, So we studied the other open source browser framework, embedded in our form, completed the product requirements, the following to do a record and share.

Since the product is to be commercially available, the issue of open source and open source agreements must be considered. The two components of GECKOFX and Cefsharp are researched, in which GECKOFX open source license is BSD Mpl,cefsharp Open source license.

  Cefsharp

CEF (Chromium Embedded Framework, Embedded Chromium framework) is a library developed by C/D + +. At present, Google Chrome (Google browser), Chromium browser, opera, etc. are based on the CEF-centric, WebKit engine browser.

Cefsharp components: https://www.nuget.org/packages/CefSharp.WinForms/49.0.1. Note that the NuGet package is downloaded, you need to install it locally, the Cefsharp and. NET framework versions should correspond, and CEF is not adaptive x86/x64, you must select a target, the downloaded package is the same with x86 and x64 dependent components , choose to use according to the target, where the core depends on the DLL: CefSharp.Core.dll, CefSharp.dll, CefSharp.WinForms.dll.

Code section:

  

1 Private voidFormwebbroswer_load (Objectsender, EventArgs e)2         {3Initbroswer ("https://www.cnblogs.com");4         }5 6         Private voidinitbroswer (String URL)7         {8             if(!cef.isinitialized)9             {Ten                 varSettings =Newcefsettings () One                 { ALocale ="ZH-CN", -Acceptlanguagelist ="ZH-CN", -Multithreadedmessageloop =true the                 }; - cef.initialize (settings); -  - Cef.enablehighdpisupport (); +             } -              +M_broswer =Newchromiumwebbrowser (URL); AM_broswer. Dock =DockStyle.Fill; at M_panel. Controls.Add (m_broswer); -         } -  -         Private voidM_textboxurl_keydown (Objectsender, KeyEventArgs e) -         { -             if(E.keydata = =keys.enter) in             { -                 if(M_broswer! =NULL) to                 { + M_broswer. Load (m_textboxurl.text); -                 } the             } *}

Attention:

    • It is best not to cef.initialize multiple browsers in the same process (settings), there may be problems;
    • Cef.enablehighdpisupport () can effectively solve the problem of screen flicker with high rate of separation.

Effect:

Geckofx

  GECKOFX is a component of the Skybound studio developed by an open source for the convenience of linking the Gecko engine (the most important browser is Firefox) to a. NET Form app.

geckofx:https://www.nuget.org/packages/geckofx45, download the same time also to consider the. NET framework version and the target platform, x86 and x64 are really different packages, as needed to download. Dependent components mainly include Geckofx-core.dll, Geckofx-winforms.dll, and run-time environment XULRunner.

Write code:

  

1  Private ReadOnlyString Xulrunnerpath = Application.startuppath +"/xulrunner";2         PrivateGeckowebbrowser M_webbrowser;3 4          PublicFormwebbroswer ()5         {6 InitializeComponent ();7             if(!xpcom.isinitialized)8             {9 xpcom.initialize (xulrunnerpath);Ten             } One         } A  -         Private voidFormwebbroswer_load (Objectsender, EventArgs e) -         { theM_webbrowser =NewGeckowebbrowser (); -M_webbrowser.dock =DockStyle.Fill; -  - M_panelContainer.Controls.Add (m_webbrowser); +  -M_webbrowser.navigate ("https://www.sina.com.cn/"); +}

Effect:

Note:geckofx Win64,. NET FrameWork4.0 versions are not easy to find, there are memory leak issues with individual versions, so choose carefully.

Embedded Webbroswer in WinForm

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.