Gtk.ToggleButton Class
A button that can be toggled on and off.

See Also: ToggleButton Members

Syntax

public class ToggleButton : Button

Remarks

A Gtk.ToggleButton is a Gtk.Button 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.

C# Example

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;
	}

}
		

Requirements

Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: 2.12.0.0