gtk-sharpGtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.Gtk.MenuShellA is a that implements a drop down menu.
A is a that implements a drop down menu consisting of a list of objects which can be navigated and activated by the user to perform application functions.
It is commonly dropped down by activating a in a or in another , it can also be popped up by activating a . Other composite widgets such as the can pop up a as well.
using System;
using Gtk;
public class MenuApp
{
public static void Main (string[] args)
{
Application.Init();
Window win = new Window ("Menu Sample App");
win.DeleteEvent += new DeleteEventHandler (delete_cb);
win.SetDefaultSize (200, 150);
VBox box = new VBox (false, 2);
MenuBar mb = new MenuBar ();
Menu file_menu = new Menu ();
MenuItem exit_item = new MenuItem("Exit");
exit_item.Activated += new EventHandler (exit_cb);
file_menu.Append (exit_item);
MenuItem file_item = new MenuItem("File");
file_item.Submenu = file_menu;
mb.Append (file_item);
box.PackStart(mb, false, false, 0);
Button btn = new Button ("Yep, that's a menu");
box.PackStart(btn, true, true, 0);
win.Add (box);
win.ShowAll ();
Application.Run ();
}
static void delete_cb (object o, DeleteEventArgs args)
{
Application.Quit ();
}
static void exit_cb (object o, EventArgs args)
{
Application.Quit ();
}
}
ConstructorA constructor.Constructor
Pointer to the C object.
Internal constructorThis is an internal constructor, and should not be used by user code.PropertyGLib.Property("accel-group")Gtk.AccelGroupSets or obtains the which holds global accelerators for the menu.The associated with the menu.
This accelerator group needs to also be added to all windows that this menu is being used in with , in order for those windows to support all the accelerators contained in this group.
PropertyGLib.Property("accel-path")System.StringSets an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed.void
The main purpose of this function is to spare the programmer the inconvenience of having to call on each menu item that should support runtime user changable accelerators. Instead, by just calling on their parent, each menu item of this menu, that contains a label describing its purpose, automatically gets an accel path assigned.
PropertyGLib.Property("active")Gtk.WidgetReturns the selected menu item from the menu.The that was last selected in the menu. If a selection has not yet been made, the first menu item is selected.
This is used by the .
MethodSystem.Void
a , should be a
a
a
a
a Adds a new to a (table) menu.The number of 'cells' that
an item will occupy is specified by ,
, and
. These each represent the leftmost,
rightmost, uppermost and lower column and row numbers of the table.
(Columns and rows are indexed from zero).Note that this function is not related to .MethodSystem.Void
The that the menu will be attached to.
The user supplied callback function that will be called when the menu calls .
Attaches the menu to the widget and provides a detacher.
Attaches the menu to the widget and provides a callback function that will be invoked when the menu calls during its destruction.
PropertyGLib.Property("attach-widget")Gtk.WidgetReturns the that the menu is attached to.The that the menu is attached to.MethodSystem.VoidDetaches the menu from the widget to which it had been attached.
This function will call the detacher, provided when the function was called.
MethodGtk.Widget[]
To be added.
To be added.To be added.To be added.PropertyGLib.GTypeGType Property.a Returns the native value for .PropertyGtk.Container+ContainerChild
To be added.
To be added.To be added.To be added.PropertyGLib.Property("monitor")System.Int32The number of the monitor on which the menu should be popped up.a EventGLib.Signal("move-scroll")Gtk.MoveScrollHandlerTo be added.To be added.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideMoveScroll", Type=typeof(Gtk.Menu))System.Void
To be added.
Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidRemoves the menu from the screen.MethodSystem.VoidDisplays a menu and makes it available for selection.This is a convenience overload that calls
with some default arguments.MethodSystem.Void
The menu shell containing the triggering menu item, or .
The menu item whose activation triggered the popup, or .
A user supplied function used to position the menu, or .
The mouse button which was pressed to initiate the event.
The time at which the activation event occurred.
Displays a menu and makes it available for selection.
Applications can use this function to display context-sensitive menus, and will typically supply for the , , and parameters. The default menu positioning function will position the menu at the current mouse cursor position.
The parameter should be the mouse button pressed to initiate the menu popup. If the menu popup was initiated by something other than a mouse button press, such as a mouse button release or a keypress, button should be zero(0).
The parameter should be the time stamp of the event that initiated the popup. If such an event is not available, use instead.
using System;
using Gtk;
class PopupSample
{
Window win;
Menu menu;
static void Main (string[] args)
{
new PopupSample (args);
}
PopupSample (string[] args)
{
Application.Init ();
win = new Window ("Menu.Popup sample");
win.SetDefaultSize (400, 300);
win.DeleteEvent += new DeleteEventHandler (OnWinDelete);
menu = new Menu ();
MenuItem hello = new MenuItem ("Hello");
hello.Activated += new EventHandler (OnHelloActivated);
hello.Show ();
menu.Append (hello);
Label label = new Label ("Right Click me");
EventBox eventbox = new EventBox ();
eventbox.ButtonPressEvent += new ButtonPressEventHandler (OnEventBoxPressed);
eventbox.Add (label);
win.Add (eventbox);
win.ShowAll ();
Application.Run ();
}
private void OnEventBoxPressed (object o, ButtonPressEventArgs args)
{
if (args.Event.button == 3)
menu.Popup (null, null, null, 3, Gtk.Global.CurrentEventTime);
}
private void OnHelloActivated (object o, EventArgs args)
{
Console.WriteLine ("Hello Activated");
}
private void OnWinDelete (object o, DeleteEventArgs args)
{
Application.Quit ();
}
}
MethodSystem.Obsolete("Replaced by overload without IntPtr argument")System.Void
The menu shell containing the triggering menu item, or .
The menu item whose activation triggered the popup, or .
A user supplied function used to position the menu, or .
Ignored.
The mouse button which was pressed to initiate the event.
The time at which the activation event occurred.
Obsolete. Replaced by .MethodSystem.Void
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.
To be added.To be added.MethodSystem.Void
The to move.
The new position to place . Positions are numbered from 0 to n-1.
Moves a to a new position within the .MethodSystem.VoidRepositions the menu according to its position function.PropertyGLib.Property("reserve-toggle-size")System.BooleanTo be added.To be added.To be added.PropertyGdk.ScreenThe physical screen this menu is placed on.a MethodSystem.Void
a Selects the specified menu item within the menu.
This is used by the and should not be used by anyone else.
PropertyGLib.Property("tearoff-state")System.BooleanSets or obtains the tearoff state of the menu.Returns if the menu is currently torn off.
A menu is normally displayed as drop down menu which persists as long as the menu is active. It can also be displayed as a tearoff menu which persists until it is closed or reattached.
PropertyGLib.Property("tearoff-title")System.StringThe title of this menu when it is torn offan object of type PropertySystem.StringSets or obtains the title for the menu.The title of the menu, or if the menu has no title set on it. This string is owned by the widget and should not be modified or freed.
The title is displayed when the menu is shown as a tearoff menu.