Разработка приложения с графическим интерфейсом пользователя. Курсовая. Кафедра Цифровые технологии и моделирование
Скачать 0.64 Mb.
|
this->Controls->Add(this->button2); this->Controls->Add(this->radioButton2); this->Controls->Add(this->radioButton1); this->Controls->Add(this->button1); this->Controls->Add(this->textBox2); this->Controls->Add(this->label2); this->Controls->Add(this->textBox1); this->Controls->Add(this->label1); this->Controls->Add(this->chart1); this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog; this->Name = L"MainForm"; this->Text = L"Главное окно"; (cli::safe_cast (cli::safe_cast this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void Button1_Click(Object^ sender, EventArgs^ e) { if (textBox1->Text != "" && textBox2->Text != "" && textBox3->Text != "" && textBox4->Text != "") { try { a1 = atoi(static_cast a2 = atoi(static_cast xmin = atoi(static_cast xmax = atoi(static_cast if (xmin < xmax) { chart1->Series[0]->Points->Clear(); double y; dataGridView1->Rows->Clear(); if (radioButton1->Checked == true) { chart1->Series[0]->LegendText = "a1cos^2x + a2sin^2x"; label3->Text = "Функция a1cos^2x + a2sin^2x"; label4->Text = "График функции a1cos^2x + a2sin^2x"; function = "Функция a1cos^2x + a2sin^2x"; for (double i = xmin; i < xmax; i += 0.1) { y = a1 * (1 + cos(2 * i * 3.14 / 180.0)) / 2 + a2 * (1 - cos(2 * i * 3.14 / 180.0)) / 2; chart1->Series[0]->Points->AddXY(i, y); dataGridView1->Rows->Add(y, i); } } else { chart1->Series[0]->LegendText = "a1x + a2sin^2x"; label3->Text = "Функция a1x + a2sin^2x"; label4->Text = "График функции a1x + a2sin^2x"; function = "Функция a1x + a2sin^2x"; for (double i = xmin; i < xmax; i += 0.1) { y = a1 * i + a2 * (1 - cos(2 * i * 3.14 / 180.0)) / 2; chart1->Series[0]->Points->AddXY(i, y); dataGridView1->Rows->Add(y, i); } } } } catch (...) { MessageBox::Show("Ошибка при вводе данных!", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error); } } } private: System::Void Button2_Click(Object^ sender, EventArgs^ e) { if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { try { File::WriteAllText(saveFileDialog1->FileName, function); File::AppendAllText(saveFileDialog1->FileName, "\n" + a1 + " " + a2); File::AppendAllText(saveFileDialog1->FileName, "\n" + xmin + " " + xmax); for (int i = 0; i < dataGridView1->Rows->Count; i++) { if (dataGridView1[0, i]->Value != NULL) { File::AppendAllText(saveFileDialog1->FileName, "\n" + dataGridView1[0, i]->Value + " " + dataGridView1[1, i]->Value); } } } catch (...) { MessageBox::Show("Ошибка при сохранении данных в файл!", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error); } } } private: System::Void Button3_Click(Object^ sender, EventArgs^ e) { Windows::Forms::DialogResult result = openFileDialog1->ShowDialog(); if (result == Windows::Forms::DialogResult::OK) { try { cli::array dataGridView1->Rows->Clear(); dataGridView1->RowCount = lines->Length - 3; cli::array a1 = atoi(static_cast a2 = atoi(static_cast temp = lines[2]->Split(L' '); xmin = atoi(static_cast xmax = atoi(static_cast textBox1->Text = a1.ToString(); textBox2->Text = a2.ToString(); textBox3->Text = xmin.ToString(); textBox4->Text = xmax.ToString(); for (int i = 3; i < lines->Length; i++) { cli::array dataGridView1[0, i - 3]->Value = values[0]; dataGridView1[1, i - 3]->Value = values[1]; } chart1->Series[0]->Points->Clear(); double y; if (lines[0] == "Функция a1cos^2x + a2sin^2x") { chart1->Series[0]->LegendText = "a1cos^2x + a2sin^2x"; label3->Text = "Функция a1cos^2x + a2sin^2x"; label3->Text = "График функции a1cos^2x + a2sin^2x"; function = "Функция a1cos^2x + a2sin^2x"; for (double i = xmin; i < xmax; i += 0.1) { y = a1 * (1 + cos(2 * i * 3.14 / 180.0)) / 2 + a2 * (1 - cos(2 * i * 3.14 / 180.0)) / 2; chart1->Series[0]->Points->AddXY(i, y); dataGridView1->Rows->Add(y, i); } } else if (lines[0] == "Функция a1x + a2sin^2x") { chart1->Series[0]->LegendText = "a1x + a2sin^2x"; label3->Text = "Функция a1x + a2sin^2x"; label4->Text = "График функции a1x + a2sin^2x"; function = "Функция a1x + a2sin^2x"; for (double i = xmin; i < xmax; i += 0.1) { y = a1 * i + a2 * (1 - cos(2 * i * 3.14 / 180.0)) / 2; chart1->Series[0]->Points->AddXY(i, y); dataGridView1->Rows->Add(y, i); } } } catch (...) { MessageBox::Show("Ошибка при загрузке данных из файла!", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error); } } } };} |