I am not a professional coder. This code is working fine as it is now.
----------
But I want to add an event to this class, that will look similar to a clasic button event, like this:
private void BasicButon_Click(object sender, EventArgs e) { ... }
and fire it up from Form1.
I have no idea how to implement it.
Please modify my code and inject in it this event functionality, then post it as an answer. Thank you.
What I have tried:
class BasicButon
{
int size = 2;
public int grf = 1;
public void Draw(int x, int y, PaintEventArgs e)
{
Point[] triunghi1 = { new Point(x + 12 * size, y + 3 * size), new Point(x + 12 * size, y - 3 * size), new Point(x + 17 * size, y) };
switch (grf)
{
case 1:
e.Graphics.FillPolygon(new SolidBrush(Color.Red), triunghi1);
break;
case 2:
e.Graphics.FillPolygon(new SolidBrush(Color.Blue), triunghi1);
break;
}
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
bb.grf = 1;
}
BasicButon bb = new BasicButon();
private void Form1_Paint(object sender, PaintEventArgs e)
{
bb.Draw(20, 20, e);
}
}