[Gtk-sharp-list] Userdata in signal handlers?
Peter Johanson
latexer at gentoo.org
Mon Feb 19 12:42:14 EST 2007
On Mon, Feb 19, 2007 at 11:38:34AM +0100, Jesper K. Pedersen wrote:
> I am making a small application where I have a range of "short-cut"
> buttons for opening a window with particular datasets.
>
>
> All my shortcut buttons are going to the same event handler but as my
> buttons are created with a label using markup language I cant seem to
> read the label value of it.
>
> 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?
>
> Any hints are greatly appreciated.
Probably the best way would be to create references to all your buttons
from glade, then use the first "object o" parameter cast as a button to
compare against them. Roughly:
class MyWindow
{
public MyWindow ()
{
Glade.XML gxml = new Glade.XML (null, "gui.glade", "MyWindow", null);
gxml.Autoconnect (this);
}
[Glade.Widget]
private Button Button1;
[Glade.Widget]
private Button Button2;
private void OnClicked (object o, EventArgs e)
{
Button b = o as Button;
if (b == null) {
return;
}
if (b == Button1) {
// Do some button1 logic here
} else if (b == Butto2) {
// Do some button2 logic here
}
}
}
HTH,
-pete
--
Peter Johanson
<latexer at gentoo.org>
More information about the Gtk-sharp-list
mailing list