mail-archives/gtk-sharp-list/2004-February/003314.html

139 строки
4.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] Glade signals with GtkSharp handlers
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:scooch%40noggle.biz">
<META NAME="robots" CONTENT="index,nofollow">
<LINK REL="Previous" HREF="003311.html">
<LINK REL="Next" HREF="003306.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] Glade signals with GtkSharp handlers
</H1>
<B>Joe Scaduto
</B>
<A HREF="mailto:scooch%40noggle.biz"
TITLE="[Gtk-sharp-list] Glade signals with GtkSharp handlers">scooch@noggle.biz
</A><BR>
<I>Tue, 03 Feb 2004 16:25:56 -0500</I>
<P><UL>
<LI> Previous message: <A HREF="003311.html">[Gtk-sharp-list] Glade signals with GtkSharp handlers
</A></li>
<LI> Next message: <A HREF="003306.html">[Gtk-sharp-list] Gtk-sharp on OS X
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#3314">[ date ]</a>
<a href="thread.html#3314">[ thread ]</a>
<a href="subject.html#3314">[ subject ]</a>
<a href="author.html#3314">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>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,&quot;file.glade&quot;, &quot;window2&quot;, 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:
&gt;<i> Joe,
</I>&gt;<i>
</I>&gt;<i> You need to sub-class the EventArgs class. Something like this:
</I>&gt;<i>
</I>&gt;<i> public class MyEventArgs : EventArgs
</I>&gt;<i> {
</I>&gt;<i> private readonly string str;
</I>&gt;<i>
</I>&gt;<i> public MyEventArgs(string str)
</I>&gt;<i> {
</I>&gt;<i> this.str = str;
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i> public string StrValue
</I>&gt;<i> {
</I>&gt;<i> get { return str;}
</I>&gt;<i> }
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i> You can delare your delegate like this:
</I>&gt;<i>
</I>&gt;<i> public delegate void MyEventHandler(object sender, MyEventArgs args);
</I>&gt;<i>
</I>&gt;<i> In the class you want to signal the event declare the event something
</I>&gt;<i> like this:
</I>&gt;<i>
</I>&gt;<i> public event MyEventHandler MyEventName;
</I>&gt;<i>
</I>&gt;<i> To signal the event in your class do something like this:
</I>&gt;<i>
</I>&gt;<i> MyEventArgs args = new MyEventArgs(&quot;Whatever String I am passing&quot;);
</I>&gt;<i> MyEventName(this, args);
</I>&gt;<i>
</I>&gt;<i> A class connecting to your event would declare a handler like this:
</I>&gt;<i>
</I>&gt;<i> public void OnMyEventName(object o, MyEventArgs args)
</I>&gt;<i> {
</I>&gt;<i> string eventString = args.StrValue;
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i> and they would connect their handler to your delegate like this:
</I>&gt;<i>
</I>&gt;<i> whateverobject.MyEventName += new MyEventHandler(OnMyEventName);
</I>&gt;<i>
</I>&gt;<i> I hope that helps.
</I>&gt;<i>
</I>&gt;<i> -Calvin
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> On Mon, 2004-02-02 at 18:43, Joe Scaduto wrote:
</I>&gt;<i> &gt; Hi,
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; I am using Glade 2 to create my base application &quot;look and feel&quot; and I
</I>&gt;<i> &gt; want to connect a signal to a handler in my gtksharp application but I
</I>&gt;<i> &gt; need to pass extra data to the handler (such as a string). From what I
</I>&gt;<i> &gt; have been told the 'Object' field in Glade 2 allows you to pass whatever
</I>&gt;<i> &gt; data to a handler you want but I am not sure how to get this data in a
</I>&gt;<i> &gt; gtksharp signal handler. I only know of 2 parameters for the handler:
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; public someHandler (object o, EventArgs args)
</I>&gt;<i> &gt; {}
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; Any information would be greatly appreciated
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; Thanks,
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; Joe
</I>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI> Previous message: <A HREF="003311.html">[Gtk-sharp-list] Glade signals with GtkSharp handlers
</A></li>
<LI> Next message: <A HREF="003306.html">[Gtk-sharp-list] Gtk-sharp on OS X
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#3314">[ date ]</a>
<a href="thread.html#3314">[ thread ]</a>
<a href="subject.html#3314">[ subject ]</a>
<a href="author.html#3314">[ author ]</a>
</LI>
</UL>
</body></html>