[Gtk-sharp-list] Userdata in signal handlers?
Nikolaos Georgiou
ngeor at freemail.gr
Mon Feb 19 06:02:12 EST 2007
Jesper K. Pedersen wrote:
> Is it possible to attach a piece of userdata to each button with a
> value that makes it easy to check which button was calling the event
> handler?
>
Hi,
I searched a bit in the documentation but I didn't find anything useful.
The GLib.Object does have some methods for getting and setting custom
properties but they are protected.
Since you're using Glade, I would map those Gtk.Button objects to some
fields:
[Glade.Widget()]
private Gtk.Button btnOne;
[Glade.Widget()]
private Gtk.Button btnTwo;
private void on_SomeButton_clicked(object sender,
System.EventArgs e)
{
if (sender == btnOne)
System.Console.WriteLine("Hello from first button");
else if (sender == btnTwo)
System.Console.WriteLine("Hello from second button");
else
System.Console.WriteLine("This is quite interesting");
}
Oh and check out the Glade# Code Generator:
http://eric.extremeboredom.net/projects/gladesharpcodegenerator/
it can produce the glade code for you.
--
Nikolaos Georgiou
More information about the Gtk-sharp-list
mailing list