gtk-sharp 2.12.0.0 Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. A button that can be toggled on and off. A is a which will remain 'pressed-in' when clicked. Clicking again will cause the toggle button to return to its normal state. This is useful if you need to maintain the state of a button. using Gtk; using System; public class ToggleButtonApp { ToggleButton btn; public static int Main (string[] args) { new ToggleButtonApp(); return 0; } public ToggleButtonApp() { Application.Init (); Window win = new Window ("ToggleButton Tester"); win.SetDefaultSize (200, 150); win.DeleteEvent += new DeleteEventHandler (Window_Delete); btn = new ToggleButton ("Unselected"); btn.Active = false; btn.Toggled += new EventHandler (btn_toggled); win.Add (btn); win.ShowAll (); Application.Run (); } void btn_toggled (object obj, EventArgs args) { Console.WriteLine ("Button Toggled"); if (btn.Active) { btn.Label = "Unselected"; } else { btn.Label = "Selected"; } } static void Window_Delete (object obj, DeleteEventArgs args) { Application.Quit (); args.RetVal = true; } } Gtk.Button Method Gtk.ToggleButton Creates a new with a text label. a containing the message to be placed in the toggle button. a new . Creates a new with a text label. Method System.Void Emits the event Emits the event on the . There is no good reason for an application ever to call this function. Constructor Internal constructor Pointer to the C object. This is an internal constructor, and should not be used by user code. Constructor Creates a new object Creates a new , which is a . A widget should be packed inside the toggle button using . Label label = new Label(); ToggleButton btn = new ToggleButton (); btn.Add(label); Constructor Creates a new with a text label. a containing the message to be placed in the toggle button. Creates a new with a text label. ToggleButton btn = new ToggleButton ("ToggleButton"); Property System.Boolean The Mode of the an object of type The Mode of the Sets whether the button is displayed as a separate indicator and label. You can call this function on a or a with = to make the button look like a normal button This function only effects instances of classes like and that derive from , not instances of itself. Property System.Boolean Determines if the has an intermediate state. an object of type If the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a , and the current values in that range are inconsistent, you may want to display the toggle in an "in between" state. This function turns on "in between" display. Normally you would turn off the inconsistent state again if the user toggles the . This has to be done manually, only affects visual appearance, it does not affect the semantics of the . GLib.Property("inconsistent") Property System.Boolean Get or set the active an object of type Get or set the active. Get: Queries a and returns its current state. Returns if the toggle button is pressed in and if it is raised. if (btn.Active) { Console.WriteLine("The ToggleButton is pressed in"); } else { Console.WriteLine("The ToggleButton is raised"); } Set: Sets the status of the toggle button. Set to if you want the GtkToggleButton to be 'pressed in', and to raise it. This action causes the toggled signal to be emitted. // set the togglebutton active // and appear "pressed in" btn.Active = true; GLib.Property("active") Property System.Boolean Determines the drawing style of a or an object of type The DrawIndicator property can be set to to make or look like a normal . GLib.Property("draw-indicator") Event System.EventHandler Triggered when the is clicked. Should be connected if you wish to perform an action whenever the state changes. ToggleButton btn = new ToggleButton("ToggleButton"); btn.Toggled += new EventHandler (btn_toggled); void btn_toggled (object obj, EventArgs args) { // code for toggled event here } GLib.Signal("toggled") Property GLib.GType GType Property. a Returns the native value for . Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Constructor Protected Constructor. a Chain to this constructor if you have manually registered a native value for your subclass. System.Obsolete