1 /* Button Boxes 2 * 3 * The Button Box widgets are used to arrange buttons with padding. 4 */ 5 6 using System; 7 using Gtk; 8 9 namespace GtkDemo 10 { 11 [Demo ("Button Boxes", "DemoButtonBox.cs")] 12 public class DemoButtonBox : Gtk.Window 13 { DemoButtonBox()14 public DemoButtonBox () : base ("Button Boxes") 15 { 16 BorderWidth = 10; 17 18 // Add Vertical Box 19 VBox mainVbox = new VBox (false,0); 20 Add (mainVbox); 21 22 // Add Horizontal Frame 23 Frame horizontalFrame = new Frame ("Horizontal Button Boxes"); 24 mainVbox.PackStart (horizontalFrame, true, true, 10); 25 VBox vbox = new VBox (false, 0); 26 vbox.BorderWidth = 10; 27 horizontalFrame.Add (vbox); 28 29 // Pack Buttons 30 vbox.PackStart (CreateButtonBox (true, "Spread", 40, ButtonBoxStyle.Spread), true, true, 0); 31 vbox.PackStart (CreateButtonBox (true, "Edge", 40, ButtonBoxStyle.Edge), true, true, 5); 32 vbox.PackStart (CreateButtonBox (true, "Start", 40, ButtonBoxStyle.Start), true, true, 5); 33 vbox.PackStart (CreateButtonBox (true, "End", 40, ButtonBoxStyle.End), true, true, 5); 34 35 // Add Vertical Frame 36 Frame verticalFrame = new Frame ("Vertical Button Boxes"); 37 mainVbox.PackStart (verticalFrame, true, true, 10); 38 HBox hbox = new HBox (false, 0); 39 hbox.BorderWidth = 10; 40 verticalFrame.Add (hbox); 41 42 // Pack Buttons 43 hbox.PackStart(CreateButtonBox (false, "Spread", 30, ButtonBoxStyle.Spread), true, true, 0); 44 hbox.PackStart(CreateButtonBox (false, "Edge", 30, ButtonBoxStyle.Edge), true, true, 5); 45 hbox.PackStart(CreateButtonBox (false, "Start", 30, ButtonBoxStyle.Start), true, true, 5); 46 hbox.PackStart(CreateButtonBox (false, "End", 30, ButtonBoxStyle.End), true, true, 5); 47 48 ShowAll (); 49 } 50 51 // Create a Button Box with the specified parameters CreateButtonBox(bool horizontal, string title, int spacing, ButtonBoxStyle layout)52 private Frame CreateButtonBox (bool horizontal, string title, int spacing, ButtonBoxStyle layout) 53 { 54 Frame frame = new Frame (title); 55 Gtk.ButtonBox bbox ; 56 57 if (horizontal) 58 bbox = new Gtk.HButtonBox (); 59 else 60 bbox = new Gtk.VButtonBox (); 61 62 bbox.BorderWidth = 5; 63 frame.Add (bbox); 64 65 // Set the appearance of the Button Box 66 bbox.Layout = layout; 67 bbox.Spacing = spacing; 68 69 bbox.Add (new Button (Stock.Ok)); 70 bbox.Add (new Button (Stock.Cancel)); 71 bbox.Add (new Button (Stock.Help)); 72 73 return frame; 74 } 75 OnDeleteEvent(Gdk.Event evt)76 protected override bool OnDeleteEvent (Gdk.Event evt) 77 { 78 Destroy (); 79 return true; 80 } 81 } 82 } 83