Pegging extended info (e.g a URL) to Label for Click event in Windows Forms app
Posted on 2004-09-05
Hey all -
Here's the problem. I have an app that gets notices from the database, and outputs a Label to the form for each notice (basically just containing a headline of what the notice is about). Each notice (Label) needs to be clickable, and when the user clicks, the form needs to open up a browser window at a URL corresponding to the clicked Label. I have all of it working except for the part of the code that is able to distinguish which Label was actually clicked.
Ideally, I'd like to just set an event argument for each label that contains the URL to visit (but such that all the labels use the same event method). I can't tell a way to do this without creating my own delegate, EventArgs subclass, and Label subclass, though...and if I did it, it would be too specialized to this one case (unless I'm looking at it wrong).
Currently, the hack I have is maintaining a class array with all the URLs, and then setting the length of each label to (500 + i), where i is that label's index within the URL array. But really, I don't want to have to maintain a separate array, and I sure as heck don't want to have to encode indices in the Length field. How else can I peg arbitrary data to these labels? (Also note that I can't use the label's Text field, since some notices will have the same "headline.")