Mono WebBrowser with WebKit [Gtk# not WinForms]

For long time I have looking for displayin web pages on Mono by using Gtk#…And thanks to this post I came across with WebKit solution!

monologo

WebKit is as they define in their page:

WebKit is an open source web browser engine. WebKit is also the name of the Mac OS X system framework version of the engine that’s used by Safari, Dashboard, Mail, and many other OS X applications. WebKit’s HTML and JavaScript code began as a branch of the KHTML and KJS libraries from KDE. This website is also the home of S60‘s S60 WebKit development.

Well after looking to the simple solution that is made in shana.worldofcoding.com, I give a try to my solution and here it is:

<pre>using System;
using Gtk;
using WebKit;

namespace browserapp {
 class browser {

 public static void Main () {
 Application.Init ();
 Window window = new Window ("BROWSER");
 window.SetSizeRequest(240,300)</pre>
</pre>
<div id=":h0">
<pre>;
 window.Destroyed += delegate (object sender, EventArgs e) {
 Application.Quit ();
 };
 ScrolledWindow scrollWindow = new ScrolledWindow ();
 WebView webView = new WebView ();
 webView.SetSizeRequest(240,250);
 webView.Open ("mono-project.com");
 scrollWindow.Add (webView);</pre>
<pre>
 Label name=new Label();
 name.Text="BrowserExample:";</pre>
<pre>
 Fixed fixed1=new Fixed();
 fixed1.SetSizeRequest(240,300);</pre>
<pre>
 fixed1.Put(name,0,0);
 fixed1.Put(scrollWindow,0,50);</pre>
<pre>
 window.Add (fixed1);
 window.ShowAll ();
 Application.Run ();
 }
 }
}

<pre>

In my Debian Lenny:

“apt-get install mono-2.0-devel gtk-sharp2 libwebkit1.0-cil”

“gmcs -pkg:gtk-sharp-2.0 -pkg:webkit-sharp-1.0 web.cs”

“mono web.exe”

The Ouput:

Reference:

[1.] http://shana.worldofcoding.com/en/browser.html
kick it on DotNetKicks.com

About these ads