I'm not sure I entirely understand your question, is this what you are looking for? First, you need to create an EventArgs class that will notify the listeners which rectangle should be genereated:
public class NewRectangleEventArgs : EventArgs
{
public int ID;
public int X;
public int Y;
public int Width;
public int Height;
public NewRectangleEventArgs(int ID, int X, int Y, int Width, int Height)
{
this.ID = ID;
this.X = X;
this.Y = Y;
this.Width = Width;
this.Height = Height;
}
}
Next, you need to create an event in your for class that others can register to:
public EventHandler<NewRectangleEventArgs> OnNewRectangle;
Now, other classes can register the event when they have a handle to your form:
form.OnNewRectangle += new EventHandler<NewRectangleEventArgs>(NewRectangleEventHandler);
With NewRectangleEventHandler being a method like:
public void NewRectangleEventHandler(object sender, NewRectangleEventArgs args)
{
}
Finally, your form needs to raise the event whenever a new rectangle should be generated:
if(OnNewRectangle != null)
OnNewRectangle(this, new NewRectangleEventArgs(0, e.X, e.Y, 20, 20));
Hope this helps :) regards