gtk-sharpGtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.Gtk.ButtonA 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;
}
}
ConstructorCreates 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
Pointer to the C object.
Internal constructorThis is an internal constructor, and should not be used by user code.Constructor
a containing the message to be placed in the toggle button.
Creates a new with a text label.Creates a new with a text label.
ToggleButton btn = new ToggleButton ("ToggleButton");PropertyGLib.Property("active")System.BooleanGet or set the activean 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;
PropertyGLib.Property("draw-indicator")System.BooleanDetermines the drawing style of a or an object of type The DrawIndicator property can be set to to make
or look like a normal .
PropertyGLib.GTypeGType Property.a Returns the native value for .PropertyGLib.Property("inconsistent")System.BooleanDetermines 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 .
PropertySystem.BooleanThe 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.
MethodGtk.ToggleButton
a containing the message to be placed in the toggle button.
Creates a new with a text label.a new .Creates a new with a text label.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideToggled", Type=typeof(Gtk.ToggleButton))System.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidEmits the eventEmits the event on the . There is no good reason for an application ever to call this function.EventGLib.Signal("toggled")System.EventHandlerTriggered 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
}