[Gtk-sharp-list] Proper design for creating windows
Matthew Beckler
mbeckler at wins-inc.com
Thu Jul 14 16:22:21 EDT 2005
Hello everyone,
I have seen in various places that you can create your programs by
extending the basic Gtk.Window, but you can also just create a new
instance of a window. I am wondering which is the 'more correct' way to
do this. I have included equivalent examples for both ways.
Inheriting from Gtk.Window:
class MyWindow : Gtk.Window
{
public MyWindow () : base ("Driver")
{
this.Title = "This is the title of MyWindow";
this.SetDefaultSize (400, 300);
this.DeleteEvent += new DeleteEventHandler
(OnMyWindowDelete);
Label label = new Label("This label is the only thing
here");
this.Add(label);
this.ShowAll ();
}
private void OnMyWindowDelete (object o, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
[STAThread]
static void Main(string[] args)
{
Application.Init();
new MyWindow();
Application.Run();
}
}
Creating a new Gtk.Window:
class MyWindow
{
private static void OnMyWindowDelete (object o, DeleteEventArgs
args)
{
Application.Quit ();
args.RetVal = true;
}
[STAThread]
static void Main(string[] args)
{
Application.Init();
Gtk.Window win = new Window("This is the title of
MyWindow");
win.Title = "This is the title of MyWindow";
win.SetDefaultSize (400, 300);
win.DeleteEvent += new DeleteEventHandler
(OnMyWindowDelete);
Label label = new Label("This label is the only thing
here");
win.Add(label);
win.ShowAll ();
Application.Run();
}
}
Again, I am wondering which way I should be doing things.
Thanks in advance,
Matthew
More information about the Gtk-sharp-list
mailing list