gtk-sharp2.10.0.0Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.A widget used to choose from a list of valid choices.
A is a widget that allows the user to choose from a list of valid choices.
The displays the selected choice.
When activated the displays a popup which allows the user to make a new choice.
Using a is simple; build a , by calling , then appending s to it with .
Set that menu on the with .
Set the selected with ; connect to the event ; when the event occurs, check the new selected with .
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 ();
}
}
Gtk.ButtonSystem.ObsoleteMethodSystem.VoidRemoves the menu from the .ConstructorInternal constructor
Pointer to the C object.
This is an internal constructor, and should not be used by user code.ConstructorCreates a new This is the default constructor for PropertySystem.Int32Retrieves the index of the currently selected .an object of type The s are numbered from top to bottom, starting with 0.PropertyGtk.WidgetThe menu of options.an object of type GLib.Property("menu")EventSystem.EventHandlerEmitted when the selection is changed.GLib.Signal("changed")MethodSystem.VoidSelects the menu item specified by making it the newly selected value for the .
a PropertyGLib.GTypeGType Property.a Returns the native value for .MethodSystem.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.ConstructorProtected Constructor.
a Chain to this constructor if you have manually registered a native value for your subclass.System.Obsolete