In c# forms I have created a new paint method:
private void thisPolygon(PaintEventArgs e)
{
Pen clrBlue = new Pen(Color.Blue, 3);
Point[] Wst = new Point[5];
Wst[0] = new Point(20, 350);
Wst[1] = new Point(110, 200);
Wst[2] = new Point(200, 190);
Wst[3] = new Point(210, 275);
Wst[4] = new Point(190, 400);
Wst[5] = new Point(50, 390);
e.Graphics.DrawPolygon(clrBlue, Wst);
}
Now, how do I call it? I can’t make it work, this doesn’t work:
private void Form1_Load(object sender, EventArgs e)
{
thisPolygon(); ///I've tried adding some stuff in brackets area, failed.
}
You have a few different problems.
(1) Array Capacity. Your array is initialized with 5 storage locations, but you are attempting to set a sixth value.
Change this to.
Remember that arrays are zero-based indexed.
(2) Not using OnPaint. You’re calling
thisPolygonin theOnLoadmethod, which won’t persist your drawing. Move your call to theOnPaintmethod of the form.(3) Not passing PaintEventArgs. You’re not passing in any event arguments to your
thisPolygonmethod, and it won’t even compile as it is. Pass in the paint arguments from theOnPaintmethod.