I want to use WebBrowser Control in Mono Windows F

2019-07-10 07:21发布

问题:

I am really confused about how can i use webbrowser control in my windows form mono application(that can run on windows and Mac). I found this only link on this topic but it is not like a tutorial so i can't understand a thing.

I found Mono.webbrowser.dll from Mono library and added into reference of project in visual studio.

     IWebBrowser browser= Mono.WebBrowser.Manager.GetNewInstance(Platform.Winforms);

then i added this line and it is causing some dependency exception. I must be missing some basics so kindly help me.

回答1:

First of all, I will highly discourage you to use this webbrowser implementation in the first place.

Cross platform WebBrowser Support in Mono is still experimental and use browsers pretty outdated: version of Firefox (Gecko) and IE (IE 5 or 6). It means that it doesn't support any of the new features of websites done in the recent years.

Furthermore, the way interoperability is done (through COM) and the original design back in .Net do not make it a good candidate for strong support either from .Net team nor Mono one. What I mean is as it exists today, it will probably disappear in the coming years.

Especially when considering that there are already pretty good alternatives out there like

  • CefGlue which is mono compatible or
  • CefSharp and the fact that
  • Ms is pushing a brand new browser: Edge.

Note: Cef stands for Chromium embedded framework and then Cef wrappers like CefGlue/Sharp enables the use of a Chrome with all the supported features.

The link you provided appears as not understoodable because it's not intended really for developpers using Mono without knowing how to build it (or its dependencies like gtk-sharp). If you really want to go this way, you must first try to learn more on Mono or dependencies like gtk-sharp. Depending on what you're trying to achieve, you either need:

  • gluezilla (Firefox/Gecko). It should work out of the box. But you must change the Platform to Unix.
  • SHDocVw.dll, mshtml.dll, BrowseUI.dll (MSIE)