Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace ProjectForm {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private:
- System::Collections::Generic::List<line> lines;
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog;
- private: System::Windows::Forms::Button^ btnOpen;
- 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->openFileDialog = (gcnew System::Windows::Forms::OpenFileDialog());
- this->btnOpen = (gcnew System::Windows::Forms::Button());
- this->SuspendLayout();
- //
- // openFileDialog
- //
- this->openFileDialog->DefaultExt = L"txt";
- this->openFileDialog->FileName = L"openFileDialog";
- this->openFileDialog->Filter = L"Текстовые файлы (*.txt)|*.txt|Все файлы (*.*)|*.*";
- this->openFileDialog->Title = L"Открыть файл";
- this->openFileDialog->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &MyForm::openFileDialog_FileOk);
- //
- // btnOpen
- //
- this->btnOpen->Location = System::Drawing::Point(49, 61);
- this->btnOpen->Name = L"btnOpen";
- this->btnOpen->Size = System::Drawing::Size(223, 189);
- this->btnOpen->TabIndex = 0;
- this->btnOpen->Text = L"Открыть";
- this->btnOpen->UseVisualStyleBackColor = true;
- this->btnOpen->Click += gcnew System::EventHandler(this, &MyForm::btnOpen_Click_1);
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(352, 315);
- this->Controls->Add(this->btnOpen);
- this->Name = L"MyForm";
- this->Text = L"MyForm";
- this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
- this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
- this->ResumeLayout(false);
- }
- #pragma endregion
- private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
- lines.Clear();
- unit(T);
- }
- private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
- {
- Graphics^ g = e->Graphics;
- g->Clear(Color::HotPink);
- Rectangle rect = Form::ClientRectangle;
- Pen^ blackPen = gcnew Pen(Color::Blue);
- blackPen->Width = 4;
- for (int i = 0; i < lines.Count; i++)
- {
- g->DrawLine(blackPen, lines[i].start.x, lines[i].start.y, lines[i].end.x, lines[i].end.y);
- //
- vec A, B;
- point2vec(lines[i].start, A);
- point2vec(lines[i].end, B);
- vec A1, B1;
- timesMatVec(T, A, A1);
- timesMatVec(T, B, B1);
- point a, b;
- vec2point(A1, a);
- vec2point(B1, b);
- g->DrawLine(blackPen, a.x, a.y, b.x, b.y);
- }
- //
- }
- private: System::Void openFileDialog_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e)
- {
- }
- private: System::Void btnOpen_Click_1(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
- {
- wchar_t fileName[1024];
- for (int i = 0; i < openFileDialog->FileName->Length; i++)
- fileName[i] = openFileDialog->FileName[i];
- fileName[openFileDialog->FileName->Length] = '\0';
- std::ifstream in;
- in.open(fileName);
- if (in.is_open())
- {
- lines.Clear();
- std::string str;
- getline(in, str);
- while (in)
- {
- if ((str.find_first_not_of(" \t\r\n") != std::string::npos)
- && (str[0] != '#'))
- {
- std::stringstream s(str);
- line l;
- s >> l.start.x >> l.start.y >> l.end.x >> l.end.y;
- std::string linename;
- s >> linename;
- l.name = gcnew String(linename.c_str());
- lines.Add(l);
- }
- getline(in, str);
- }
- }
- this->Refresh();
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement