delegate problem?
-
my application contain three forms: frmMain(mdiContainer) frmEditable frmTools private void frmEditable_MouseDown(object sender, MouseEventArgs e) { choice1Enable = true; if (choice1Enable) { Generating(0, e.X, e.Y, 20, 20); } } i want to capture this events using delegate..it is located in frmEditAble form. actually i want that when a user click on frmTools's Rectangle label. it should be displayed a rectangle on frmEditable thorugh delegate.. how can i do this
hghghgh
-
my application contain three forms: frmMain(mdiContainer) frmEditable frmTools private void frmEditable_MouseDown(object sender, MouseEventArgs e) { choice1Enable = true; if (choice1Enable) { Generating(0, e.X, e.Y, 20, 20); } } i want to capture this events using delegate..it is located in frmEditAble form. actually i want that when a user click on frmTools's Rectangle label. it should be displayed a rectangle on frmEditable thorugh delegate.. how can i do this
hghghgh
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