On Fri, 2002-06-21 at 16:36, Glenn Pierce wrote:
> 
> Hi I have just started looking at C# / GtkSharp and have attached a
> ported version of the Button Boxes program that is taken from the
> gtk-demo app if anyone is interested ?
> 
> I'm sure it can be improved.

This is great!

To compile it, install gtk# and run mcs with these flags:

        mcs --unsafe -o ButtonBoxes.exe -r glib-sharp -r pango-sharp -r
        atk-sharp -r gdk-sharp -r gtk-sharp -r gdk-imaging-sharp
        ButtonBoxes.cs

Duncan.
// ButtonBoxes.cs : Button Boxes App
//
// Author: Glenn Pierce <[EMAIL PROTECTED]>
//
// <c> 2002 Glenn Pierce

namespace GtkSharp.Samples {

        using System;
        using Gtk;
        using GtkSharp;

        public class ButtonBoxApp {

                public static void Main (string[] args)
                {
                        Application.Init();
                        Window win = new Window ("Button Boxes");
                        win.DeleteEvent += new EventHandler (delete_cb);

                        VBox main_vbox = new VBox (false, 0);

                        Frame frame_horz = new Frame ("Horizontal Button Boxes");
                        main_vbox.PackStart (frame_horz, true, true, 10);

                        VBox vbox = new VBox (false, 0);
                        vbox.BorderWidth = 10;
                        frame_horz.EmitAdd(vbox);       

                        vbox.PackStart (create_bbox (true, "Spread", 40, 
Gtk.ButtonBoxStyle.Spread) , true, true, 5 );
                        vbox.PackStart (create_bbox (true, "Edge", 40, 
Gtk.ButtonBoxStyle.Edge) , true, true, 5 );
                        vbox.PackStart (create_bbox (true, "Start", 40, 
Gtk.ButtonBoxStyle.Start) , true, true, 5 );
                        vbox.PackStart (create_bbox (true, "End", 40, 
Gtk.ButtonBoxStyle.End) , true, true, 5 );

                        Frame frame_vert = new Frame ("Vertical Button Boxes");
                        main_vbox.PackStart (frame_vert, true, true, 10);       
                        
                        HBox hbox = new HBox (false, 0);
                        hbox.BorderWidth = 10;
                        frame_vert.EmitAdd(hbox);

                        hbox.PackStart (create_bbox (false, "Spread", 30, 
Gtk.ButtonBoxStyle.Spread) , true, true, 5 );
                        hbox.PackStart (create_bbox (false, "Edge", 30, 
Gtk.ButtonBoxStyle.Edge) , true, true, 5 );
                        hbox.PackStart (create_bbox (false, "Start", 30, 
Gtk.ButtonBoxStyle.Start) , true, true, 5 );
                        hbox.PackStart (create_bbox (false, "End", 30, 
Gtk.ButtonBoxStyle.End) , true, true, 5 );
                        
                        win.EmitAdd (main_vbox);
                        win.BorderWidth = 10;
                        win.ShowAll ();

                        Application.Run ();
                }

                static void delete_cb (object o, EventArgs args)
                {
                        SignalArgs sa = (SignalArgs) args;
                        Application.Quit ();
                        sa.RetVal = true;
                }

                private static Frame create_bbox (bool horizontal, string title, int 
spacing, Gtk.ButtonBoxStyle layout)
                {
                  Frame frame;
                  ButtonBox bbox;
                  Button button;
                                        
                  frame = new Frame (title);

                  if (horizontal)
                     bbox = new HButtonBox();
                  else
                     bbox = new VButtonBox();
                  
                  bbox.BorderWidth = 5;
                  frame.EmitAdd(bbox);
 
                  bbox.LayoutStyle = layout;
                  bbox.Spacing = spacing;
                                                     
                  button = Button.NewFromStock("gtk-ok");
                  bbox.EmitAdd(button);
                
                  button = Button.NewFromStock("gtk-cancel");
                  bbox.EmitAdd(button);

                  button = Button.NewFromStock("gtk-help");
                  bbox.EmitAdd(button);
                
                  return frame;
                }
                
        }
}

Reply via email to