I am trying to use the following code which use to draw polygon base on user coordinate input I found the code on the following link (Drawing a polygon according to the input coordinates), I just started to learn about C# and I am so interested to learn. The code is:
void pictureBox1_Paint(object sender, PaintEventArgs e) {
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.Clear(Color.White);
// draw the shading background:
List<Point> shadePoints = new List<Point>();
shadePoints.Add(new Point(0, pictureBox1.ClientSize.Height));
shadePoints.Add(new Point(pictureBox1.ClientSize.Width, 0));
shadePoints.Add(new Point(pictureBox1.ClientSize.Width,
pictureBox1.ClientSize.Height));
e.Graphics.FillPolygon(Brushes.LightGray, shadePoints.ToArray());
// scale the drawing larger:
using (Matrix m = new Matrix()) {
m.Scale(4, 4);
e.Graphics.Transform = m;
List<Point> polyPoints = new List<Point>();
polyPoints.Add(new Point(10, 10));
polyPoints.Add(new Point(12, 35));
polyPoints.Add(new Point(22, 35));
polyPoints.Add(new Point(24, 22));
// use a semi-transparent background brush:
using (SolidBrush br = new SolidBrush(Color.FromArgb(100, Color.Yellow))) {
e.Graphics.FillPolygon(br, polyPoints.ToArray());
}
e.Graphics.DrawPolygon(Pens.DarkBlue, polyPoints.ToArray());
foreach (Point p in polyPoints) {
e.Graphics.FillEllipse(Brushes.Red,
new Rectangle(p.X - 2, p.Y - 2, 4, 4));
}
}
I deleted part of the code and the error was gone, however the code didn't work. The error are:
Severity Code Description Project File Line Suppression State Error CS0103 The name 'pictureBox1' does not exist in the current context WinFormsApp8
Severity Code Description Project File Line Suppression State Error CS1061 'Form1' does not contain a definition for 'Form1_Paint' and no accessible extension method 'Form1_Paint' accepting a first argument of type 'Form1' could be found (are you missing a using directive or an assembly reference?) WinFormsApp8