Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Header.h"
- namespace Practice1 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- train* tr;
- /// <summary
- /// Сводка для MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::ComponentModel::IContainer^ components;
- protected:
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- train* tr;
- private: System::Windows::Forms::TextBox^ text1;
- private: System::Windows::Forms::TextBox^ text4;
- private: System::Windows::Forms::TextBox^ text3;
- private: System::Windows::Forms::TextBox^ text2;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::Label^ label4;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::Timer^ timer1;
- private: System::Windows::Forms::Button^ button1;
- private: Graphics^ g;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- this->text1 = (gcnew System::Windows::Forms::TextBox());
- this->text4 = (gcnew System::Windows::Forms::TextBox());
- this->text3 = (gcnew System::Windows::Forms::TextBox());
- this->text2 = (gcnew System::Windows::Forms::TextBox());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->label4 = (gcnew System::Windows::Forms::Label());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->SuspendLayout();
- //
- // text1
- //
- this->text1->Location = System::Drawing::Point(12, 663);
- this->text1->Name = L"text1";
- this->text1->Size = System::Drawing::Size(100, 22);
- this->text1->TabIndex = 4;
- this->text1->Text = L"700";
- //
- // text4
- //
- this->text4->Location = System::Drawing::Point(330, 663);
- this->text4->Name = L"text4";
- this->text4->Size = System::Drawing::Size(100, 22);
- this->text4->TabIndex = 5;
- this->text4->Text = L"1";
- //
- // text3
- //
- this->text3->Location = System::Drawing::Point(224, 663);
- this->text3->Name = L"text3";
- this->text3->Size = System::Drawing::Size(100, 22);
- this->text3->TabIndex = 6;
- this->text3->Text = L"10";
- //
- // text2
- //
- this->text2->Location = System::Drawing::Point(118, 663);
- this->text2->Name = L"text2";
- this->text2->Size = System::Drawing::Size(100, 22);
- this->text2->TabIndex = 7;
- this->text2->Text = L"300";
- //
- // button2
- //
- this->button2->Location = System::Drawing::Point(628, 652);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(84, 54);
- this->button2->TabIndex = 11;
- this->button2->Text = L"GO";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(12, 634);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(15, 16);
- this->label1->TabIndex = 12;
- this->label1->Text = L"X";
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(115, 634);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(16, 16);
- this->label2->TabIndex = 13;
- this->label2->Text = L"Y";
- //
- // label3
- //
- this->label3->AutoSize = true;
- this->label3->Location = System::Drawing::Point(221, 634);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(17, 16);
- this->label3->TabIndex = 14;
- this->label3->Text = L"H";
- //
- // label4
- //
- this->label4->AutoSize = true;
- this->label4->Location = System::Drawing::Point(327, 634);
- this->label4->Name = L"label4";
- this->label4->Size = System::Drawing::Size(17, 16);
- this->label4->TabIndex = 15;
- this->label4->Text = L"N";
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(484, 652);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(108, 54);
- this->button1->TabIndex = 16;
- this->button1->Text = L"Start";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(746, 652);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(97, 54);
- this->button3->TabIndex = 17;
- this->button3->Text = L"Clear";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
- //
- // timer1
- //
- this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::Color::WhiteSmoke;
- this->ClientSize = System::Drawing::Size(1128, 754);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->label4);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->text2);
- this->Controls->Add(this->text3);
- this->Controls->Add(this->text4);
- this->Controls->Add(this->text1);
- this->Name = L"MyForm";
- this->Text = L"MyForm";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- //Start
- int x; int y; int move_count;
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- int x = System::Convert::ToDouble(text1->Text);
- int y = System::Convert::ToDouble(text2->Text);
- int h = System::Convert::ToDouble(text3->Text);
- int n = System::Convert::ToDouble(text4->Text);
- tr = new train(x, y, h, n);
- g = MyForm::CreateGraphics();
- tr->draw(g);
- }
- //Clear
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- Graphics^ im = MyForm::CreateGraphics();
- im->Clear(Color::WhiteSmoke);
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- int x = System::Convert::ToDouble(text1->Text);
- int y = System::Convert::ToDouble(text2->Text);
- int h = System::Convert::ToDouble(text3->Text);
- int n = System::Convert::ToDouble(text4->Text);
- tr = new train(x, y, h, n);
- g = MyForm::CreateGraphics();
- this->timer1->Enabled = !this->timer1->Enabled;
- }
- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
- int x = System::Convert::ToDouble(text1->Text);
- int y = System::Convert::ToDouble(text2->Text);
- int h = System::Convert::ToDouble(text3->Text);
- int n = System::Convert::ToDouble(text4->Text);
- if (x + 100.0 > this->Size.Width) {
- move_count = 0;
- x = 0;
- }
- g->Clear(Color::WhiteSmoke);
- train tr(x, y, h, n);
- tr.move(move_count);
- tr.draw(g);
- move_count+=10;
- if (move_count > 100) {
- move_count = 0;
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment