I have 3 classes in my program:
Arrow (it contains the logic for drawing arrow, and all required information about it, like: starting point, ending point, etc.)
Form1 (that contains the drawing area(basically panel), where this arrow will be located in the future)
UserControl, is located in
Form1(I didForm1.Controls.Add(UserControl)). It has aForm1as a parent. In thisUserControl, I have a button, when I click it, an arrow should be drawn on theForm1's drawing area.And I'm so confused with the logic that this program should have. I tried to create
Arrowclass object in theUserControl.Button_Click(), and call all the Arrow's methods from there, but I can't access to Form1's controls. I also thought maybe I can create object ofArrowin theForm1. So I tried to subscribe eventUserControl.Button_Click()with someForm1's delegate, but I don't know how to do it. In this case, does delegate and the method that this delegate have as a reference should be Static?
So this is how my code looks like. (I little bit simplified and shortened my classes) Arrow:
public class Arrow
{
public Point PointBeginning { get => pointBeginning; set => pointBeginning = value; }
public Point PointEnding { get => pointEnding; set => pointEnding = value; }
public int ArrowClickCounter { get => arrowClickCounter; set => arrowClickCounter = value; }
public void Draw(object sender, MouseEventArgs e)
{
//code for drawing
}
}
Form1:
public class Form1
{
public delegate void DrawArrowDelegate(object sender, MouseEventArgs e);
DrawArrowDelegate drawArrowDelegate = DrawArrow;
/* .. */
private void DrawArrow(object sender, MouseEventArgs e)
{
Arrow arrow = new Arrow();
arrow.PointBegining = //some point
arrow.PointEnding = //some another point
arrow.Draw(sender, e);
}
}
UserControl:
public class UserControl
{
/*...*/
private void button_MouseClick(object sender, MouseEventArgs e)
{
//And here i somehow want to call delegate. But don't know how :(
}
}
Sorry for such confused code :(
Can you please recommend me something?