using System; using Gtk; public class DocumentForm : Window { public DocumentForm () : base ("Document") { this.SetDefaultSize (200, 100); this.DeleteEvent += new DeleteEventHandler (OnDocumentFormDelete); VBox components = new VBox(); // size group SizeGroup sizeGroup = new SizeGroup(SizeGroupMode.Horizontal); // kind _kindComboBox = AddComboBox( components, sizeGroup, "kind:", new string[] {"Text", "Spreadsheet", "Presentation"} ); // name _nameEntry = AddEntry(components, sizeGroup, "name:"); // isPublic _isPublicCheckButton = AddCheckButton(components, sizeGroup, "is public:"); // spacing components.PackStart(new Label(), true, true, 0); // buttons HBox buttonsHBox = new HBox(); Label spacer = new Label(); buttonsHBox.PackStart(spacer, true, true, 0); Button saveButton = new Button(Stock.Save); saveButton.Clicked += new EventHandler(OnSaveClick); buttonsHBox.PackStart(saveButton, false, false, 2); Button closeButton = new Button(Stock.Close); closeButton.Clicked += new EventHandler(OnCloseClick); buttonsHBox.PackStart(closeButton, false, false, 2); components.PackStart(buttonsHBox, false, false, 7); this.Add(components); this.ShowAll (); } static ComboBox AddComboBox( VBox components, SizeGroup sizeGroup, string labelText, string[] options) { HBox hbox = new HBox(); Label label = new Label(); label.Text = labelText; label.SetAlignment(1F, 0.5F); hbox.PackStart(label, false, false, 2); ComboBox comboBox = ComboBox.NewText(); foreach(string option in options) { comboBox.AppendText(option); } hbox.PackStart(comboBox, false, false, 2); sizeGroup.AddWidget(label); components.PackStart(hbox, false, false, 2); return comboBox; } static Entry AddEntry(VBox components, SizeGroup sizeGroup, string labelText) { HBox hbox = new HBox(); Label label = new Label(); label.Text = labelText; label.SetAlignment(1F, 0.5F); hbox.PackStart(label, false, false, 2); Entry entry = new Entry(); hbox.Add(entry); sizeGroup.AddWidget(label); components.PackStart(hbox, false, false, 2); return entry; } static CheckButton AddCheckButton(VBox components, SizeGroup sizeGroup, string labelText) { HBox hbox = new HBox(); Label label = new Label(); label.Text = labelText; label.SetAlignment(1F, 0.5F); hbox.PackStart(label, false, false, 2); CheckButton checkButton = new CheckButton(); hbox.Add(checkButton); sizeGroup.AddWidget(label); components.PackStart(hbox, false, false, 2); return checkButton; } void OnSaveClick (object sender, EventArgs a) { Console.WriteLine("'Save' clicked"); } void OnCloseClick (object sender, EventArgs a) { Application.Quit (); } void OnDocumentFormDelete (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } ComboBox _kindComboBox; Entry _nameEntry; CheckButton _isPublicCheckButton; }