using Gtk; public class MyMenu : Gtk.Window { public MyMenu() : base("Menu Example") { VBox vbox = new VBox(false, 2); MenuBar menubar = new MenuBar(); vbox.PackStart(menubar, false, false, 0); Menu filemenu = new Menu(); MenuItem file = new MenuItem("File"); file.Submenu = filemenu; MenuItem Quit = new MenuItem("Quit"); Quit.Activated += delegate { Gtk.Application.Quit(); }; filemenu.Append(Quit); menubar.Append(file); Add(vbox); ShowAll(); } public static void Main() { Application.Init(); new MyMenu(); Application.Run(); } }
using Gtk; public class MyMenu : Gtk.Window { public MyMenu() : base("Menu Example") { VBox vbox = new VBox(false, 2); MenuBar menubar = new MenuBar(); vbox.PackStart(menubar, false, false, 0); Menu filemenu = new Menu(); MenuItem file = new MenuItem("File"); file.Submenu = filemenu; MenuItem New = new MenuItem("New"); filemenu.Append(New); MenuItem Open = new MenuItem("Open"); filemenu.Append(Open); SeparatorMenuItem separator = new SeparatorMenuItem(); filemenu.Append(separator); MenuItem Quit = new MenuItem("Quit"); Quit.Activated += delegate { Gtk.Application.Quit(); }; filemenu.Append(Quit); menubar.Append(file); Add(vbox); ShowAll(); } public static void Main() { Application.Init(); new MyMenu(); Application.Run(); } }This code example creates a menu with multiple items, including "New", "Open", and "Quit". It also includes a separator line to visually separate the "Open" and "Quit" items. The menu is displayed in a window using the Gtk.VBox layout manager. Package Library: Gtk# Library