简体   繁体   English

Linux上的Mono WebBrowser控件

[英]Mono WebBrowser control on Linux

I'm writing an application that I would like to have run under either Windows or Linux. 我正在编写一个我希望在Windows或Linux下运行的应用程序。 Since it is a text application, the obvious choice for rendering and user interaction is to use html in a WebBrowser control. 由于它是一个文本应用程序,渲染和用户交互的明显选择是在WebBrowser控件中使用html。 This all works great using Mono in Windows, but I'm absolutely stumped on how to get it to work using Mono in Linux. 这一切在Windows中使用Mono都非常有用,但我绝对不知道如何在Linux中使用Mono让它工作。 I'm running Linux Mint 17, have MonoDevelop and Firefox installed. 我正在运行Linux Mint 17,安装了MonoDevelop和Firefox。 The following code snippet compiles and runs, but when the application launches, wbMain does not show up. 以下代码片段编译并运行,但是当应用程序启动时, wbMain不会显示。 The application dies when trying to render an html string using wbMain . 尝试使用wbMain呈现html字符串时应用程序死亡。

private System.Windows.Forms.Panel pnlMain;
private Mono.WebBrowser.IWebBrowser wbMain;
private System.Windows.Forms.Button btnGo;

this.pnlMain = new System.Windows.Forms.Panel();
this.wbMain = Mono.WebBrowser.Manager.GetNewInstance();
this.wbMain.Activate();
this.btnGo = new System.Windows.Forms.Button();
this.pnlMain.SuspendLayout();
this.SuspendLayout();
// 
// pnlMain
// 
this.pnlMain.Controls.Add((System.Windows.Forms.Control)this.wbMain.Window);
this.pnlMain.Controls.Add(this.btnGo);
this.pnlMain.Location = new System.Drawing.Point(12, 1);
this.pnlMain.Name = "pnlMain";
this.pnlMain.Size = new System.Drawing.Size(260, 248);
this.pnlMain.TabIndex = 0;
// 
// wbMain
// 
this.wbMain.Resize(260, 216);
this.wbMain = Mono.WebBrowser.Manager.GetNewInstance();

The problem lies with your GetNewInstance() from what I understand here. 问题在于我从这里理解的GetNewInstance() GetNewInstance assumes platform of Windows by default, you need to pass in your own Mono.WebBrowser.Platform for it to render in the framework you want (like Gtk). GetNewInstance默认采用Windows平台,您需要传入自己的Mono.WebBrowser.Platform ,以便在您想要的框架中呈现(如Gtk)。

Source Code 源代码

You can see in the source code I linked, the default GetNewInstance() returns Platform.Winforms ; 您可以在我链接的源代码中看到,默认的GetNewInstance()返回Platform.Winforms ;

    public static IWebBrowser GetNewInstance ()
    {
        return Manager.GetNewInstance (Platform.Winforms);
    }

Also Mono.WebBrowser has been retired in favor of WebkitSharp. 此外,Mono.WebBrowser已经退役,转而支持WebkitSharp。 You really should be using WebkitSharp to do this now. 您现在应该使用WebkitSharp来执行此操作。 WebkitSharp has had...some issues, so there's a currently open version of it called open-webkit-sharp that may work for you as well. WebkitSharp有......一些问题,因此目前有一个名为open-webkit-sharp的开放版本也可能适合你。 The code on there is at least up to date as of 2012. Whereas Mono WebBrowser and webkit-sharp haven't had any major code changes...in years, at least 5 to 7 years. 截至2012年,该代码至少是最新的。而Mono WebBrowser和webkit-sharp没有任何重大的代码更改......在几年内,至少5到7年。

I've also had good luck with the open version of Awesomium , and it's a staple of the gaming industry. 我也对Awesomium的开放版本好运 ,它是游戏行业的主要产品。 Again, the open version of Awesomium hasn't had any major updates since 2012 though. 同样,Awesomium的开放版本自2012年以来没有任何重大更新。 However, you can get the paid version of Awesomium if money/cost isn't an issue and that has had recent updates. 但是,如果金钱/费用不是问题并且最近有更新,您可以获得Awesomium的付费版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM