Advertisement
Tevronis

form

Sep 13th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.72 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace ProjectForm {
  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.  
  12.     /// <summary>
  13.     /// Summary for MyForm
  14.     /// </summary>
  15.     public ref class MyForm : public System::Windows::Forms::Form
  16.     {
  17.     public:
  18.         MyForm(void)
  19.         {
  20.             InitializeComponent();
  21.             //
  22.             //TODO: Add the constructor code here
  23.             //
  24.         }
  25.  
  26.     protected:
  27.         /// <summary>
  28.         /// Clean up any resources being used.
  29.         /// </summary>
  30.         ~MyForm()
  31.         {
  32.             if (components)
  33.             {
  34.                 delete components;
  35.             }
  36.         }
  37.     private:
  38.         System::Collections::Generic::List<line> lines;
  39.     private: System::Windows::Forms::OpenFileDialog^  openFileDialog;
  40.  
  41.     private: System::Windows::Forms::Button^  btnOpen;
  42.     private:
  43.         /// <summary>
  44.         /// Required designer variable.
  45.         /// </summary>
  46.         System::ComponentModel::Container ^components;
  47.  
  48. #pragma region Windows Form Designer generated code
  49.         /// <summary>
  50.         /// Required method for Designer support - do not modify
  51.         /// the contents of this method with the code editor.
  52.         /// </summary>
  53.         void InitializeComponent(void)
  54.         {
  55.             this->openFileDialog = (gcnew System::Windows::Forms::OpenFileDialog());
  56.             this->btnOpen = (gcnew System::Windows::Forms::Button());
  57.             this->SuspendLayout();
  58.             //
  59.             // openFileDialog
  60.             //
  61.             this->openFileDialog->DefaultExt = L"txt";
  62.             this->openFileDialog->FileName = L"openFileDialog";
  63.             this->openFileDialog->Filter = L"Текстовые файлы (*.txt)|*.txt|Все файлы (*.*)|*.*";
  64.             this->openFileDialog->Title = L"Открыть файл";
  65.             this->openFileDialog->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &MyForm::openFileDialog_FileOk);
  66.             //
  67.             // btnOpen
  68.             //
  69.             this->btnOpen->Location = System::Drawing::Point(49, 61);
  70.             this->btnOpen->Name = L"btnOpen";
  71.             this->btnOpen->Size = System::Drawing::Size(223, 189);
  72.             this->btnOpen->TabIndex = 0;
  73.             this->btnOpen->Text = L"Открыть";
  74.             this->btnOpen->UseVisualStyleBackColor = true;
  75.             this->btnOpen->Click += gcnew System::EventHandler(this, &MyForm::btnOpen_Click_1);
  76.             //
  77.             // MyForm
  78.             //
  79.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  80.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  81.             this->ClientSize = System::Drawing::Size(352, 315);
  82.             this->Controls->Add(this->btnOpen);
  83.             this->Name = L"MyForm";
  84.             this->Text = L"MyForm";
  85.             this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  86.             this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
  87.             this->ResumeLayout(false);
  88.  
  89.         }
  90. #pragma endregion
  91.     private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
  92.                  lines.Clear();
  93.                  unit(T);
  94.     }
  95.     private: System::Void MyForm_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
  96.     {
  97.                  Graphics^ g = e->Graphics;
  98.                  g->Clear(Color::HotPink);
  99.                  Rectangle rect = Form::ClientRectangle;
  100.  
  101.                  Pen^ blackPen = gcnew Pen(Color::Blue);
  102.                  blackPen->Width = 4;
  103.  
  104.                  for (int i = 0; i < lines.Count; i++)
  105.                  {
  106.                      g->DrawLine(blackPen, lines[i].start.x, lines[i].start.y, lines[i].end.x, lines[i].end.y);
  107.  
  108.                      //
  109.  
  110.                     vec A, B;
  111.                     point2vec(lines[i].start, A);
  112.                     point2vec(lines[i].end, B);
  113.                    
  114.                     vec A1, B1;
  115.                     timesMatVec(T, A, A1);
  116.                     timesMatVec(T, B, B1);
  117.  
  118.                     point a, b;
  119.                     vec2point(A1, a);
  120.                     vec2point(B1, b);
  121.                     g->DrawLine(blackPen, a.x, a.y, b.x, b.y);
  122.                  }
  123.                  //
  124.                  
  125.  
  126.     }
  127.     private: System::Void openFileDialog_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e)
  128.     {
  129.  
  130.     }
  131.    
  132. private: System::Void btnOpen_Click_1(System::Object^  sender, System::EventArgs^  e)
  133. {
  134.              if (this->openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
  135.              {
  136.                  wchar_t fileName[1024];
  137.                  for (int i = 0; i < openFileDialog->FileName->Length; i++)
  138.                      fileName[i] = openFileDialog->FileName[i];
  139.                  fileName[openFileDialog->FileName->Length] = '\0';
  140.                  std::ifstream in;
  141.                  in.open(fileName);
  142.                  if (in.is_open())
  143.                  {
  144.                      lines.Clear();
  145.                      std::string str;
  146.                      getline(in, str);
  147.                      while (in)
  148.                      {
  149.                          if ((str.find_first_not_of(" \t\r\n") != std::string::npos)
  150.                              && (str[0] != '#'))
  151.                          {
  152.                              std::stringstream s(str);
  153.                              line l;
  154.                              s >> l.start.x >> l.start.y >> l.end.x >> l.end.y;
  155.                              std::string linename;
  156.                              s >> linename;
  157.                              l.name = gcnew String(linename.c_str());
  158.                              lines.Add(l);
  159.                          }
  160.                          getline(in, str);
  161.                      }
  162.                  }
  163.                  this->Refresh();
  164.              }
  165. }
  166. };
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement