GTK#

A closer look at Buttons

Toggle Buttons

ToggleButtons are similiar to the normal button, but when clicked, may be depressed, and when you click again, they will pop back up. Click again, and they will pop back down. When popped down, the Property Active has the value "true".

Toggle buttons are the basis for check buttons and radio buttons, as such, many of the calls used for toggle buttons are inherited by radio and check buttons. I will point these out when we come to them.

        using Gtk;
        using GtkSharp;
        using System;
        using System.Drawing;

        public class togglebuttons
        {


                public static void Main(string[] args)
                {

                        Application.Init();   
      
   
                        Window window = new Window("toggle buttons");
                          
                        window.DeleteEvent += new DeleteEventHandler (delete_event);

/* Creating a new ToggleButton*/

                        ToggleButton togglebutton = new ToggleButton  ("button1");
                        togglebutton.Clicked += new EventHandler (clickedCallback);


                        window.Add(togglebutton);
                        window.ShowAll();
                             
                        Application.Run();
                        
                }

                static void delete_event (object obj, DeleteEventArgs args)
                {

                        Application.Quit();
                }

                static void clickedCallback (object obj, EventArgs args)
                {
/* Check Active Property */

                        if (((ToggleButton) obj).Active)
                                Console.WriteLine ("ToggleButton clicked, I'm activating");
                }
        }



MonoBasic example