See Also: OptionMenu Members
A Gtk.OptionMenu is a widget that allows the user to choose from a list of valid choices. The Gtk.OptionMenu displays the selected choice. When activated the Gtk.OptionMenu displays a popup Gtk.Menu which allows the user to make a new choice.
Using a Gtk.OptionMenu is simple; build a Gtk.Menu, by calling Menu(), then appending Gtk.MenuItems to it with MenuShell.Append(). Set that menu on the Gtk.OptionMenu with OptionMenu.Menu. Set the selected Gtk.MenuItem with OptionMenu.SetHistory(uint); connect to the event OptionMenu.Changed; when the OptionMenu.Changed event occurs, check the new selected Gtk.MenuItem with OptionMenu.History.
Example
using System;
using Gtk;
class OptionMenuSample
{
OptionMenu opt;
static void Main ()
{
new OptionMenuSample ();
}
OptionMenuSample ()
{
Application.Init ();
Window win = new Window ("OptionMenuSample");
win.DeleteEvent += new DeleteEventHandler (OnWinDelete);
// set up the OptionMenu
opt = new OptionMenu ();
opt.Changed += new EventHandler (OnOptionChanged);
Menu m = new Menu ();
MenuItem miOne = new MenuItem ("One");
m.Append (miOne);
MenuItem miTwo = new MenuItem ("Two");
m.Append (miTwo);
MenuItem miThree = new MenuItem ("Three");
m.Append (miThree);
// add children widgets to their parents
opt.Menu = m;
win.Add (opt);
// set the OptionMenu to a value
opt.SetHistory (2);
win.ShowAll ();
Application.Run ();
}
void OnOptionChanged (object o, EventArgs args)
{
Console.WriteLine (opt.History);
}
void OnWinDelete (object o, DeleteEventArgs args)
{
Application.Quit ();
}
}