To carry out the movement of the square in a given straight forward and backward.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int x, Tempo; int N = 4; PointF point1 = PointF(20, 160); PointF point2 = PointF(70, 160); PointF point3 = PointF(70, 210); PointF point4 = PointF(20, 210); Graphics ^g = pictureBox1->CreateGraphics(); g->Clear(System::Drawing::Color::White); Pen ^myPen = gcnew Pen(System::Drawing::Color::BlueViolet, 3); g->DrawLine(myPen, 20, 220, 340, 220); array <PointF> ^PointsXY = { point1, point2, point3,point4 }; g->DrawPolygon(myPen, PointsXY); Tempo = (int)this->numericUpDown1->Value; if (!Tempo) { MessageBox::Show("Скорость не может быть равна нулю!"); return; } for (x = 15; x < 350; x++) { g->Clear(System::Drawing::Color::White); g->DrawPolygon(myPen, PointsXY); _sleep(10); } for (x = 350; x>0; x--) { g->Clear(System::Drawing::Color::White); g->DrawPolygon(myPen, PointsXY); _sleep(10); } g->DrawLine(myPen, 20, 220, 340, 220); }
sleep, because it blocks the drawing of the interface. Use the timer. - VladD