working on a project for school and can't seem to figure out the for loop for making a polygon in a windows form. We have a set code that we have to follow but the teacher hasn't covered anything for window forms. And I don't understand what is meant by the directions.

diriections from teacher:

2. drawPoly(): Complete the ‘for loop’ to connect each vertex with its neighbor. The index should sequentially address each point in the polygon, not to exceed the number of points in the array. If the point is the last point in the array, it should be connected to the first point in the array. We should look at some pseudo code: [A Visio Diagram follows the Appendix ]
for each point indexed from 0 to the index of the last point
calculate the screen coordinates of that point
if it is the last point in the polygon
the second point of the line is the first point in the polygon
calculate the screen coordinates of the second point in the line
else
the second point of the line is the next index value
calculate the screen coordinates of the second point in the line

draw the line
end for

#pragma once


namespace ChangeSpace {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	int midY, midX, Width, Height;
	const float uNit = 10;
	const int ptLen = 3;

	void drawAxes(Graphics^ pg, Pen^ pn, System::Drawing::Font^ font1, int Width, int Height) {
		int farRight = Width - 30;
		int farBottom = Height - 50;

		pg->DrawLine(pn, midX, 20, midX, farBottom);
		pg->DrawLine(pn, 20, midY, farRight, midY);
		
		pg->DrawString(L"X+", font1, Brushes::Black, (float)(farRight - 20), (float)midY);
		pg->DrawString(L"Y+", font1, Brushes::Black, (float)midX, 10);
	}

	void drawPoly(Graphics^ pg, float poly[][ptLen], int polySize, Pen^ pn) {
		int i, x1, y1, x2, y2;

		for (i=0; i<polySize; i++) 
		{
			
		}

	}

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	
	private: System::Drawing::Font^ font1;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(15, 380);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(71, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"DRAW ME!";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(542, 423);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
 
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
 				 ///////////////////////////////////////////
				 // Declare prototype of functions
				 void DrawAxes(Graphics^, Pen^, System::Drawing::Font^, int, int);
				 void DrawPoly(Graphics^, float [][ptLen], int Size, Pen^);

				 // Declare necessary variables for drawing different line types
				 Pen^ pen1 = gcnew Pen(Color::Red); 
				 Pen^ pen2 = gcnew Pen(Color::Black);
				 Pen^ pen3 = gcnew Pen(Color::Green);
				 Pen^ pen4 = gcnew Pen(Color::Blue);

				 Graphics^ pg = CreateGraphics();
				 font1 = gcnew System::Drawing::Font("Verdana", 4, FontStyle::Regular, GraphicsUnit::Millimeter);

				 // Declare a triangle
				 float triPoly[][ptLen] = {{-.5, 0, 1}, {0, 1.0, 1}, {.5, 0, 1}};
				 // Declare a quadrilaterl
				 float quadPoly[][ptLen] = {{-1, 1, 1}, {1, 1.0, 1}, {1, -1, 1}, {-1, -1, 1}};

				 //////////////////////////////////////////
				 
				 // Creates the world space reference in the screen space
				 Width = Form1::Width;
				 Height = Form1::Height;
				 midY = Height/2;
				 midX = Width/2;

				 drawAxes(pg, pen2, font1, Width, Height);
			
				 // Here's where we send the arrays to the drawing function
				 drawPoly(pg, quadPoly, 4, pen3);
				 drawPoly(pg, triPoly, 3, pen1);				
			 }
	};
}

sorry for the long code but wasn't sure what all you gus would need.

Thanks for any help.

ohhh line 31 is where the for loop is that I need help with

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.