Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
- int coords[2][4];
- array<System::String^>^ lines = gcnew array<System::String^>(7);
- openFile(lines);
- //if не пустой
- parseFile(lines, coords);
- drawLines(coords);
- }
- void drawLines(int coords[][4]) {
- Graphics^ g;
- g = pictureBox1->CreateGraphics();
- g->DrawLine(System::Drawing::Pens::Green, coords[0][0], coords[0][1], coords[0][2], coords[0][3]);
- g->DrawLine(System::Drawing::Pens::Green, coords[1][0], coords[1][1], coords[1][2], coords[1][3]);
- }
- void openFile(array<System::String^>^ lines) {
- int i = 0;
- OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
- openFileDialog1->InitialDirectory = "c:\\";
- openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- openFileDialog1->FilterIndex = 2;
- openFileDialog1->RestoreDirectory = true;
- if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
- {
- StreamReader^ sr = gcnew StreamReader(openFileDialog1->FileName);
- try
- {
- String^ line;
- while (line = sr->ReadLine())
- {
- try {
- lines[i] = line;
- i++;
- }
- catch (IndexOutOfRangeException^ e) {
- textBox1->Text = "Ошибка";
- }
- }
- }
- finally
- {
- if (sr)
- delete (IDisposable^)sr;
- }
- }
- }
- int* parseFile(array<System::String^>^ lines, int coords[][4]) {
- try {
- bool flag = false;
- String^ line = "Line[1-2]{1}";
- String^ coord = "[0-9]{1,5}[ ][0-9]{1,5}";
- if (!Regex::IsMatch(lines[0], line, RegexOptions::IgnoreCase)) {
- throw 0;
- }
- if (!Regex::IsMatch(lines[1], coord, RegexOptions::IgnoreCase)) {
- throw 1;
- }
- if (!Regex::IsMatch(lines[2], coord, RegexOptions::IgnoreCase)) {
- throw 2;
- }
- if (!Regex::IsMatch(lines[4], line, RegexOptions::IgnoreCase)) {
- throw 4;
- }
- if (!Regex::IsMatch(lines[5], coord, RegexOptions::IgnoreCase)) {
- throw 5;
- }
- if (!Regex::IsMatch(lines[6], coord, RegexOptions::IgnoreCase)) {
- throw 6;
- }
- coords[0][0] = int::Parse(lines[1]->Split(' ')[0]);
- coords[0][1] = int::Parse(lines[1]->Split(' ')[1]);
- coords[1][0] = int::Parse(lines[2]->Split(' ')[0]);
- coords[1][1] = int::Parse(lines[2]->Split(' ')[1]);
- coords[2][0] = int::Parse(lines[5]->Split(' ')[0]);
- coords[2][1] = int::Parse(lines[5]->Split(' ')[1]);
- coords[3][0] = int::Parse(lines[6]->Split(' ')[0]);
- coords[3][1] = int::Parse(lines[6]->Split(' ')[1]);
- }
- catch (int i) {
- textBox1->Text = "Ошибка в строке " + (i + 1).ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement