Sorry for the delay, but I got sidetracked on something else.
I based my original class on the suggestions in the help file for faking a control array, which I use to have an array of usercontrols based on a textbox.
There is an AddBox procedure, which adds a new box to the array, and subscribes to the various events that I want to pass on to the main application, such as
box.Click +=new EventHandler(box_Click);
where box is the new text box, and box_Click is as follows:
private void box_Click(object sender, EventArgs e)
{
MyBoxEventArgs arg;
Coordinates c;
c = (Coordinates)((Mybox)sender).Tag;
//adjust the row and column to make them 1-based
arg = new MyBoxEventArgs(c.Row+1, c.Col+1);
try
{
Click(sender,arg);
}
catch {}
}
Briefly, the tag contains the x and y coordinates of the box in the array.
I reused the array on another form in the application, but this time I wasn't interested in the Click event, so never wrote a handler for it. Without the try...catch block, this threw an uncaught exception. Hovering the mouse oer the Click in the line Click(sender,arg), the debugger suggests that Click is an 'undefined value'.
Conversely when you reach the same point having clicked the box on the original point, Click is an event handler according to the debugger.
My question is whether there isn't a better way of dealing with this than a try...catch block? It ought to be possible to avoid the exception being thrown in the first place as there is a certain overhead involved in raising it and catching it.
Thanks for any help.
|