HICONT

MyForm

May 12th, 2022 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.87 KB | None | 0 0
  1. #pragma once
  2. #include "Header.h"
  3. namespace Practice1 {
  4.  
  5.     using namespace System;
  6.     using namespace System::ComponentModel;
  7.     using namespace System::Collections;
  8.     using namespace System::Windows::Forms;
  9.     using namespace System::Data;
  10.     using namespace System::Drawing;
  11.     train* tr;
  12.     /// <summary
  13.     /// Сводка для MyForm
  14.     /// </summary>
  15.     public ref class MyForm : public System::Windows::Forms::Form
  16.     {
  17.     public:
  18.        
  19.         MyForm(void)
  20.         {
  21.             InitializeComponent();
  22.             //
  23.             //TODO: добавьте код конструктора
  24.             //
  25.         }
  26.  
  27.     protected:
  28.         /// <summary>
  29.         /// Освободить все используемые ресурсы.
  30.         /// </summary>
  31.         ~MyForm()
  32.         {
  33.             if (components)
  34.             {
  35.                 delete components;
  36.             }
  37.         }
  38.     private: System::ComponentModel::IContainer^ components;
  39.     protected:
  40.  
  41.     private:
  42.         /// <summary>
  43.         /// Обязательная переменная конструктора.
  44.         /// </summary>
  45.  
  46.         train* tr;
  47.     private: System::Windows::Forms::TextBox^ text1;
  48.     private: System::Windows::Forms::TextBox^ text4;
  49.  
  50.  
  51.  
  52.     private: System::Windows::Forms::TextBox^ text3;
  53.  
  54.     private: System::Windows::Forms::TextBox^ text2;
  55.     private: System::Windows::Forms::Button^ button2;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.     private: System::Windows::Forms::Label^ label1;
  62.     private: System::Windows::Forms::Label^ label2;
  63.     private: System::Windows::Forms::Label^ label3;
  64.     private: System::Windows::Forms::Label^ label4;
  65.     private: System::Windows::Forms::Button^ button3;
  66.     private: System::Windows::Forms::Timer^ timer1;
  67.     private: System::Windows::Forms::Button^ button1;
  68.     private: Graphics^ g;
  69.  
  70.  
  71. #pragma region Windows Form Designer generated code
  72.            /// <summary>
  73.            /// Требуемый метод для поддержки конструктора — не изменяйте
  74.            /// содержимое этого метода с помощью редактора кода.
  75.            /// </summary>
  76.            void InitializeComponent(void)
  77.            {
  78.                this->components = (gcnew System::ComponentModel::Container());
  79.                this->text1 = (gcnew System::Windows::Forms::TextBox());
  80.                this->text4 = (gcnew System::Windows::Forms::TextBox());
  81.                this->text3 = (gcnew System::Windows::Forms::TextBox());
  82.                this->text2 = (gcnew System::Windows::Forms::TextBox());
  83.                this->button2 = (gcnew System::Windows::Forms::Button());
  84.                this->label1 = (gcnew System::Windows::Forms::Label());
  85.                this->label2 = (gcnew System::Windows::Forms::Label());
  86.                this->label3 = (gcnew System::Windows::Forms::Label());
  87.                this->label4 = (gcnew System::Windows::Forms::Label());
  88.                this->button1 = (gcnew System::Windows::Forms::Button());
  89.                this->button3 = (gcnew System::Windows::Forms::Button());
  90.                this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
  91.                this->SuspendLayout();
  92.                //
  93.                // text1
  94.                //
  95.                this->text1->Location = System::Drawing::Point(12, 663);
  96.                this->text1->Name = L"text1";
  97.                this->text1->Size = System::Drawing::Size(100, 22);
  98.                this->text1->TabIndex = 4;
  99.                this->text1->Text = L"700";
  100.                //
  101.                // text4
  102.                //
  103.                this->text4->Location = System::Drawing::Point(330, 663);
  104.                this->text4->Name = L"text4";
  105.                this->text4->Size = System::Drawing::Size(100, 22);
  106.                this->text4->TabIndex = 5;
  107.                this->text4->Text = L"1";
  108.                //
  109.                // text3
  110.                //
  111.                this->text3->Location = System::Drawing::Point(224, 663);
  112.                this->text3->Name = L"text3";
  113.                this->text3->Size = System::Drawing::Size(100, 22);
  114.                this->text3->TabIndex = 6;
  115.                this->text3->Text = L"10";
  116.                //
  117.                // text2
  118.                //
  119.                this->text2->Location = System::Drawing::Point(118, 663);
  120.                this->text2->Name = L"text2";
  121.                this->text2->Size = System::Drawing::Size(100, 22);
  122.                this->text2->TabIndex = 7;
  123.                this->text2->Text = L"300";
  124.                //
  125.                // button2
  126.                //
  127.                this->button2->Location = System::Drawing::Point(628, 652);
  128.                this->button2->Name = L"button2";
  129.                this->button2->Size = System::Drawing::Size(84, 54);
  130.                this->button2->TabIndex = 11;
  131.                this->button2->Text = L"GO";
  132.                this->button2->UseVisualStyleBackColor = true;
  133.                this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  134.                //
  135.                // label1
  136.                //
  137.                this->label1->AutoSize = true;
  138.                this->label1->Location = System::Drawing::Point(12, 634);
  139.                this->label1->Name = L"label1";
  140.                this->label1->Size = System::Drawing::Size(15, 16);
  141.                this->label1->TabIndex = 12;
  142.                this->label1->Text = L"X";
  143.                //
  144.                // label2
  145.                //
  146.                this->label2->AutoSize = true;
  147.                this->label2->Location = System::Drawing::Point(115, 634);
  148.                this->label2->Name = L"label2";
  149.                this->label2->Size = System::Drawing::Size(16, 16);
  150.                this->label2->TabIndex = 13;
  151.                this->label2->Text = L"Y";
  152.                //
  153.                // label3
  154.                //
  155.                this->label3->AutoSize = true;
  156.                this->label3->Location = System::Drawing::Point(221, 634);
  157.                this->label3->Name = L"label3";
  158.                this->label3->Size = System::Drawing::Size(17, 16);
  159.                this->label3->TabIndex = 14;
  160.                this->label3->Text = L"H";
  161.                //
  162.                // label4
  163.                //
  164.                this->label4->AutoSize = true;
  165.                this->label4->Location = System::Drawing::Point(327, 634);
  166.                this->label4->Name = L"label4";
  167.                this->label4->Size = System::Drawing::Size(17, 16);
  168.                this->label4->TabIndex = 15;
  169.                this->label4->Text = L"N";
  170.                //
  171.                // button1
  172.                //
  173.                this->button1->Location = System::Drawing::Point(484, 652);
  174.                this->button1->Name = L"button1";
  175.                this->button1->Size = System::Drawing::Size(108, 54);
  176.                this->button1->TabIndex = 16;
  177.                this->button1->Text = L"Start";
  178.                this->button1->UseVisualStyleBackColor = true;
  179.                this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  180.                //
  181.                // button3
  182.                //
  183.                this->button3->Location = System::Drawing::Point(746, 652);
  184.                this->button3->Name = L"button3";
  185.                this->button3->Size = System::Drawing::Size(97, 54);
  186.                this->button3->TabIndex = 17;
  187.                this->button3->Text = L"Clear";
  188.                this->button3->UseVisualStyleBackColor = true;
  189.                this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  190.                //
  191.                // timer1
  192.                //
  193.                this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
  194.                //
  195.                // MyForm
  196.                //
  197.                this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
  198.                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  199.                this->BackColor = System::Drawing::Color::WhiteSmoke;
  200.                this->ClientSize = System::Drawing::Size(1128, 754);
  201.                this->Controls->Add(this->button3);
  202.                this->Controls->Add(this->button1);
  203.                this->Controls->Add(this->label4);
  204.                this->Controls->Add(this->label3);
  205.                this->Controls->Add(this->label2);
  206.                this->Controls->Add(this->label1);
  207.                this->Controls->Add(this->button2);
  208.                this->Controls->Add(this->text2);
  209.                this->Controls->Add(this->text3);
  210.                this->Controls->Add(this->text4);
  211.                this->Controls->Add(this->text1);
  212.                this->Name = L"MyForm";
  213.                this->Text = L"MyForm";
  214.                this->ResumeLayout(false);
  215.                this->PerformLayout();
  216.  
  217.            }
  218. #pragma endregion
  219.     //Start
  220.            int x; int y; int move_count;
  221.     private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  222.         int x = System::Convert::ToDouble(text1->Text);
  223.         int y = System::Convert::ToDouble(text2->Text);
  224.         int h = System::Convert::ToDouble(text3->Text);
  225.         int n = System::Convert::ToDouble(text4->Text);
  226.         tr = new train(x, y, h, n);
  227.         g = MyForm::CreateGraphics();
  228.         tr->draw(g);
  229.     }
  230.     //Clear
  231.     private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  232.         Graphics^ im = MyForm::CreateGraphics();
  233.         im->Clear(Color::WhiteSmoke);
  234.     }
  235.     private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  236.         int x = System::Convert::ToDouble(text1->Text);
  237.         int y = System::Convert::ToDouble(text2->Text);
  238.         int h = System::Convert::ToDouble(text3->Text);
  239.         int n = System::Convert::ToDouble(text4->Text);
  240.         tr = new train(x, y, h, n);
  241.         g = MyForm::CreateGraphics();
  242.         this->timer1->Enabled = !this->timer1->Enabled;
  243.     }
  244.     private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
  245.         int x = System::Convert::ToDouble(text1->Text);
  246.         int y = System::Convert::ToDouble(text2->Text);
  247.         int h = System::Convert::ToDouble(text3->Text);
  248.         int n = System::Convert::ToDouble(text4->Text);
  249.  
  250.         if (x + 100.0 > this->Size.Width) {
  251.             move_count = 0;
  252.             x = 0;
  253.         }
  254.  
  255.         g->Clear(Color::WhiteSmoke);
  256.  
  257.         train tr(x, y, h, n);
  258.  
  259.         tr.move(move_count);
  260.         tr.draw(g);
  261.  
  262.         move_count+=10;
  263.         if (move_count > 100) {
  264.             move_count = 0;
  265.         }
  266.     }
  267. };
  268. }
Advertisement
Add Comment
Please, Sign In to add comment