我正在编写一个我希望在Windows或Linux下运行的应用程序。由于它是一个文本应用程序,渲染和用户交互的明显选择是在WebBrowser
控件中使用html。这一切在Windows中使用Mono都非常有用,但我绝对不知道如何在Linux中使用Mono让它工作。我正在运行Linux Mint 17,安装了MonoDevelop和Firefox。以下代码段编译并运行,但是当应用程序启动时,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);
答案 0 :(得分:5)
this.wbMain = Mono.WebBrowser.Manager.GetNewInstance();
根据我的理解,您的GetNewInstance()
存在问题。 GetNewInstance
默认采用Windows平台,您需要传入自己的Mono.WebBrowser.Platform
,以便在您想要的框架中呈现(如Gtk)。
您可以在我链接的源代码中看到,默认GetNewInstance()
会返回Platform.Winforms
;
public static IWebBrowser GetNewInstance ()
{
return Manager.GetNewInstance (Platform.Winforms);
}
Mono.WebBrowser也已退役,转而使用WebkitSharp。您现在应该使用WebkitSharp来执行此操作。 WebkitSharp有......一些问题,因此它的当前开放版本称为open-webkit-sharp也可能对您有用。截至2012年,该代码至少是最新的。而Mono WebBrowser和webkit-sharp避免了任何重大代码更改......多年来,至少5到7年。
我对Awesomium的开放版本也有好运,它是游戏行业的主要产品。同样,自2012年以来,Awesomium的开放版本还没有任何重大更新。但是,如果金钱/费用不是问题且最近有更新,您可以获得Awesomium的付费版本。