[Gtk-sharp-list] Glade signals with GtkSharp handlers
Joe Scaduto
scooch@noggle.biz
Tue, 03 Feb 2004 16:25:56 -0500
Calvin,
This definitively helps in my understanding of event handlers however, I
should have mentioned that I am connecting the handlers via Glade#.
example:
Glade.XML gxml = new Glade.XML (null,"file.glade", "window2", null);
gxml.Autoconnect (this);
So I am still not sure how I would be able to pass a string?
Joe
On Tue, 2004-02-03 at 10:18, Calvin Gaisford wrote:
> Joe,
>
> You need to sub-class the EventArgs class. Something like this:
>
> public class MyEventArgs : EventArgs
> {
> private readonly string str;
>
> public MyEventArgs(string str)
> {
> this.str = str;
> }
>
> public string StrValue
> {
> get { return str;}
> }
> }
>
> You can delare your delegate like this:
>
> public delegate void MyEventHandler(object sender, MyEventArgs args);
>
> In the class you want to signal the event declare the event something
> like this:
>
> public event MyEventHandler MyEventName;
>
> To signal the event in your class do something like this:
>
> MyEventArgs args = new MyEventArgs("Whatever String I am passing");
> MyEventName(this, args);
>
> A class connecting to your event would declare a handler like this:
>
> public void OnMyEventName(object o, MyEventArgs args)
> {
> string eventString = args.StrValue;
> }
>
> and they would connect their handler to your delegate like this:
>
> whateverobject.MyEventName += new MyEventHandler(OnMyEventName);
>
> I hope that helps.
>
> -Calvin
>
>
> On Mon, 2004-02-02 at 18:43, Joe Scaduto wrote:
> > Hi,
> >
> > I am using Glade 2 to create my base application "look and feel" and I
> > want to connect a signal to a handler in my gtksharp application but I
> > need to pass extra data to the handler (such as a string). From what I
> > have been told the 'Object' field in Glade 2 allows you to pass whatever
> > data to a handler you want but I am not sure how to get this data in a
> > gtksharp signal handler. I only know of 2 parameters for the handler:
> >
> > public someHandler (object o, EventArgs args)
> > {}
> >
> > Any information would be greatly appreciated
> >
> > Thanks,
> >
> > Joe