[Gtk-sharp-list] Bug? : Changing CheckButton.Active Fires Clicked Event

Archie Maskill galepsus at gmail.com
Fri Oct 21 12:40:51 EDT 2005


I can't quite tell if this is a bug or a feature...

When the Active property of a CheckBox is changed, a CheckBox.Clicked
event is fired.  While Clicked events often precede changes in a
CheckBox, surely a Clicked event should only represent the actual
clicking on a CheckBox by the user and not by some other indirect
means (i.e. changing Active)?

I have a GUI that directly reflects the state of some variables
somewhere.  I have overriden the OnClicked() method so that when a
CheckBox is clicked some validation can be done before the value of
the box is allowed to change.  When the validation is completed, the
Active property is changed.  Unfortunately, this causes a second
Clicked event to be fired, the validation code runs again and the
value is returned to what it was when the first physical click
occurred.  Two clicks for the price of one.  :)

I've included a short code sample below demonstrating the problem.  Is
this the correct behaviour?

Thanks,
- Archie


using System;
using Gtk;

public class MainClass
{
    public static void Main()
    {
        Application.Init();
        CheckButton cb = new CheckButton("checkbutton");
        Window w = new Window("");
        w.Add(cb);

        cb.Clicked += new EventHandler(checkbuttonClicked);
        cb.Active = true;
        cb.Active = false;
    }

    public static void checkbuttonClicked(object sender, EventArgs args)
    {
        Console.WriteLine("CheckButton was clicked");
    }
}


More information about the Gtk-sharp-list mailing list