gtk-sharp0.0.0.0neutralGtk# 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;
using GtkSharp;
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.ButtonAtk.ImplementorGLib.IWrapperGLib.IWrapperSystem.IDisposableMethodSystem.VoidRemoves the menu from the .MethodSystem.VoidDisposes the resources associated with the object.ConstructorInternal constructor
Pointer to the C object.
An instance of , wrapping the C object.This is an internal constructor, and should not be used by user code.ConstructorCreates a new an object of type This is the default constructor for PropertySystem.UInt32The for The for the class.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 an object of type EventSystem.EventHandlerEmitted when the selection is changed.ConstructorInternal constructor
GLib type for the type
Creates a new instance of OptionMenu, using the GLib-provided typeThis is a constructor used by derivative types of that would have their own GLib type assigned to it. This is not typically used by C# code.MethodSystem.VoidSelects the menu item specified by making it the newly selected value for the .
a