На этом шаге мы рассмотрим содержимое этого модуля.
Модуль формы содержит объявление класса формы. Здесь находятся конструктор и деструктор формы, созданные программистом функции обработки событий. Большую часть модуля формы формирует среда разработки. Следует обратить внимание на секцию Windows Form Designer generated code (секция — фрагмент кода, находящийся между директивами #pragma region и #pragma endregion). В ней находится функция InitializeComponent, обеспечивающая непосредственно создание и инициализацию формы и компонентов.
#pragma once namespace profit { 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> /// Сводка для Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: добавьте код конструктора // } protected: /// <summary> /// Освободить все используемые ресурсы. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::TextBox^ textBox1; protected: private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::Button^ button1; private: /// <summary> /// Требуется переменная конструктора. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Обязательный метод для поддержки конструктора - не изменяйте /// содержимое данного метода при помощи редактора кода. /// </summary> void InitializeComponent(void) { this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->label1 = (gcnew System::Windows::Forms::Label()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label3 = (gcnew System::Windows::Forms::Label()); this->button1 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // textBox1 // this->textBox1->Location = System::Drawing::Point(107, 16); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(100, 24); this->textBox1->TabIndex = 0; // // textBox2 // this->textBox2->Location = System::Drawing::Point(107, 45); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(57, 24); this->textBox2->TabIndex = 1; // // label1 // this->label1->Location = System::Drawing::Point(13, 19); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(95, 20); this->label1->TabIndex = 2; this->label1->Text = L"Сумма (руб): "; this->label1->TextAlign = System::Drawing:: ContentAlignment::MiddleRight; // // label2 // this->label2->Location = System::Drawing::Point(13, 45); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(88, 20); this->label2->TabIndex = 3; this->label2->Text = L"Срок (мес.): "; this->label2->TextAlign = System::Drawing:: ContentAlignment::MiddleRight; // // label3 // this->label3->Location = System::Drawing::Point(23, 122); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(299, 50); this->label3->TabIndex = 4; // // button1 // this->button1->Location = System::Drawing::Point(26, 84); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 5; this->button1->Text = L"Расчет"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(7, 16); this->AutoScaleMode = System::Windows::Forms:: AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(407, 218); this->Controls->Add(this->button1); this->Controls->Add(this->label3); this->Controls->Add(this->label2); this->Controls->Add(this->label1); this->Controls->Add(this->textBox2); this->Controls->Add(this->textBox1); this->Font = (gcnew System::Drawing::Font(L"Tahoma", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204))); this->FormBorderStyle = System::Windows::Forms:: FormBorderStyle::FixedSingle; this->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->MaximizeBox = false; this->Name = L"Form1"; this->StartPosition = System::Windows::Forms:: FormStartPosition::CenterScreen; this->Text = L"Доход"; this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { double sum; // сумма int period; // срок double percent; // процентная ставка double profit; // доход sum = System::Convert::ToDouble(textBox1->Text); period = System::Convert::ToInt32(textBox2->Text); if (sum < 10000) percent = 8.5; else percent = 12; profit = sum * (percent/100/12) * period; label3->Text = "Процентная ставка: " + percent.ToString("n") + "%\n" + "Доход:" + profit.ToString("c"); } }; }
Рис.1. Модуль формы программы "Доход" (Form1.h)
На следующем шаге мы рассмотрим компиляцию проекта.