- 论坛徽章:
- 0
|
mono里有个Gecko.WebControl ClassEmbed a Mozilla browser window into your Gtk# application.
C# Example
[color="blue"]using System;
[color="blue"]using Gtk;
[color="blue"]using Gecko;
[color="blue"]namespace GeckoTest
{
[color="blue"]class GeckoTest
{
WebControl moz;
Entry entry;
[color="blue"]string currentUrl;
Statusbar sb;
ProgressBar pb;
[color="blue"]static [color="blue"]void Main ([color="blue"]string[] args)
{
[color="blue"]new GeckoTest ();
}
GeckoTest ()
{
Application.Init ();
Window win = [color="blue"]new Window ([color="purple"]"GeckoTest");
win.SetDefaultSize (800, 600);
win.DeleteEvent += [color="blue"]new DeleteEventHandler (window_delete);
VBox vbox = [color="blue"]new VBox ([color="blue"]false, 1);
win.Add (vbox);
HBox tb = [color="blue"]new HBox ([color="blue"]true, 1);
Button btnBack = [color="blue"]new Button (Gtk.Stock.GoBack);
btnBack.Clicked += [color="blue"]new EventHandler (on_btnBack_clicked);
Button btnForward = [color="blue"]new Button (Gtk.Stock.GoForward);
btnForward.Clicked += [color="blue"]new EventHandler (on_btnForward_clicked);
Button btnStop = [color="blue"]new Button (Gtk.Stock.Stop);
btnStop.Clicked += [color="blue"]new EventHandler (on_btnStop_clicked);
Button btnRefresh = [color="blue"]new Button (Gtk.Stock.Refresh);
btnRefresh.Clicked += [color="blue"]new EventHandler (on_btnRefresh_clicked);
tb.Add (btnBack);
tb.Add (btnForward);
tb.Add (btnStop);
tb.Add (btnRefresh);
vbox.PackStart (tb, [color="blue"]false, [color="blue"]false, 1);
HBox hbox = [color="blue"]new HBox ([color="blue"]false, 1);
Label label = [color="blue"]new Label ([color="purple"]"Address:");
entry = [color="blue"]new Entry ([color="purple"]"URL");
entry.Activated += [color="blue"]new EventHandler (entry_activated);
Button button = [color="blue"]new Button ([color="purple"]"GO!");
button.Clicked += [color="blue"]new EventHandler (button_clicked);
hbox.PackStart (label, [color="blue"]false, [color="blue"]false, 1);
hbox.PackStart (entry, [color="blue"]true, [color="blue"]true, 1);
hbox.PackStart (button, [color="blue"]false, [color="blue"]false, 1);
vbox.PackStart (hbox, [color="blue"]false, [color="blue"]false, 1);
moz = [color="blue"]new WebControl ([color="purple"]"/tmp/csharp", [color="purple"]"GeckoTest");
moz.LinkMsg += [color="blue"]new EventHandler(on_moz_linkmessage);
vbox.PackStart(moz, [color="blue"]true, [color="blue"]true, 1);
HBox hbox2 = [color="blue"]new HBox ([color="blue"]false, 1);
vbox.PackStart (hbox2, [color="blue"]false, [color="blue"]false, 1);
sb = [color="blue"]new Statusbar ();
sb.Push (1, [color="purple"]"Welcome!");
hbox2.Add (sb);
pb = [color="blue"]new ProgressBar ();
pb.Orientation = ProgressBarOrientation.LeftToRight;
hbox2.Add (pb);
win.ShowAll ();
Application.Run ();
}
[color="blue"]void window_delete ([color="blue"]object obj, DeleteEventArgs args)
{
Application.Quit();
}
[color="blue"]void button_clicked ([color="blue"]object obj, EventArgs args)
{
LoadHtml (entry.Text.Trim());
}
[color="blue"]void on_moz_linkmessage ([color="blue"]object obj, EventArgs args)
{
sb.Pop (1);
sb.Push (1, moz.LinkMessage);
}
[color="blue"]void entry_activated ([color="blue"]object obj, EventArgs args)
{
button_clicked (obj, args);
}
[color="blue"]void LoadHtml ([color="blue"]string URL)
{
moz.LoadUrl (URL);
}
[color="blue"]void on_btnBack_clicked ([color="blue"]object obj, EventArgs args)
{
moz.GoBack();
}
[color="blue"]void on_btnStop_clicked ([color="blue"]object obj, EventArgs args)
{
moz.StopLoad();
}
[color="blue"]void on_btnForward_clicked ([color="blue"]object obj, EventArgs args)
{
moz.GoForward();
}
[color="blue"]void on_btnRefresh_clicked ([color="blue"]object obj, EventArgs args)
{
moz.Reload(0);
}
}
}
Namespace: Gecko
Assembly: gecko-sharp 2.0.0.0 (in gecko-sharp.dll)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/809/showart_82002.html |
|