mail-archives/gtk-sharp-list/2004-October/005025.html

87 строки
3.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] How to reference an object, given it's name?
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:jonpryor%40vt.edu">
<META NAME="robots" CONTENT="index,nofollow">
<LINK REL="Previous" HREF="005023.html">
<LINK REL="Next" HREF="005026.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] How to reference an object, given it's name?
</H1>
<B>Jonathan Pryor
</B>
<A HREF="mailto:jonpryor%40vt.edu"
TITLE="[Gtk-sharp-list] How to reference an object, given it's name?">jonpryor@vt.edu
</A><BR>
<I>Thu, 28 Oct 2004 06:28:12 -0400</I>
<P><UL>
<LI> Previous message: <A HREF="005023.html">[Gtk-sharp-list] How to reference an object, given it's name?
</A></li>
<LI> Next message: <A HREF="005026.html">[Gtk-sharp-list] How to reference an object, given it's name?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#5025">[ date ]</a>
<a href="thread.html#5025">[ thread ]</a>
<a href="subject.html#5025">[ subject ]</a>
<a href="author.html#5025">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>On Thu, 2004-10-28 at 00:10, Peter K. Gale wrote:
&gt;<i> Say you have an array of button objects named buttonA, buttonB, etc, and a
</I>&gt;<i> corresponding array of event objects named eventA, eventB, etc. I am
</I>&gt;<i> trying to find a clean way to link buttonX.Clicked with an action on
</I>&gt;<i> eventX.
</I>&gt;<i>
</I>&gt;<i> When a button is clicked, the handler will be passed a reference to that
</I>&gt;<i> button object. Extracting the name of the button and changing the string
</I>&gt;<i> from &quot;buttonX&quot; to &quot;eventX&quot; is easy. I am having problems trying to use the
</I>&gt;<i> string &quot;eventX&quot; to reference the event object of the same name. Any ideas?
</I>&gt;<i> If the process is as clean as I hope it is, it's probably one line of code.
</I>
I assume that the number of buttons and events is the same. If this is
the case, you need do only two things: (1) ensure that the order of
buttons matches the order of events, e.g.
Button[] buttons = {buttonA, buttonB, buttonC};
Event[] events = {eventA, eventB, eventC};
(2) Use IList.IndexOf to find the index of the button, then index the
event array with the same index:
IList b = buttons;
int index = b.IndexOf (myButton);
Event e = events[index];
If the number of buttons and events is *not* equal, then you'll have to
develop some mapping mechanism between buttons and events, possibly via
a Hashtable.
- Jon
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI> Previous message: <A HREF="005023.html">[Gtk-sharp-list] How to reference an object, given it's name?
</A></li>
<LI> Next message: <A HREF="005026.html">[Gtk-sharp-list] How to reference an object, given it's name?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#5025">[ date ]</a>
<a href="thread.html#5025">[ thread ]</a>
<a href="subject.html#5025">[ subject ]</a>
<a href="author.html#5025">[ author ]</a>
</LI>
</UL>
</body></html>