Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ТПКС-лаба2

.docx
Скачиваний:
10
Добавлен:
17.01.2020
Размер:
61.66 Кб
Скачать

МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ ХАРКІВСЬКИЙ НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ РАДІОЕЛЕКТРОНІКИ

Кафедра КІТАМ

ЗВІТ з лабораторної роботи № 2 з дисципліни: «Технологіі програмування комп’ютерних систем»

Варіант 2

Виконав: Перевірив:

ст. гр. АКТСІу -17-1 ст. викл. каф. КІТАМ

Черкашин В.А. Бронніков А.І.

Юрченко В.Р.

Харків 2019

1 РОЗРОБКА ПРОСТИХ .NET ПРОГРАМ ЗАСОБАМИ C++/CLI. ОБРОБКА ПОДІЙ

1.1 Мета роботи

Створення найпростішої віконної процедури з обробками подій засобами С++/CLI на основі Windows Forms у середовищі Microsoft Visual Studios 2010.

1.2 Практична частина та лістинг програмного коду

Файл MyForm.cpp:

#include "MyForm.h"

using namespace System;

using namespace System::Windows::Forms;

[STAThreadAttribute]

void Main(array<String^>^ args) {

Application::EnableVisualStyles();

Application::SetCompatibleTextRenderingDefault(false);

laba2::MyForm form;

Application::Run(% form);

}

Файл MyForm.h:

#pragma once

namespace laba2 {

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>

/// Сводка для MyForm

/// </summary>

public ref class MyForm : public System::Windows::Forms::Form

{

public:

MyForm(void)

{

InitializeComponent();

//

//TODO: добавьте код конструктора

//

}

protected:

/// <summary>

/// Освободить все используемые ресурсы.

/// </summary>

~MyForm()

{

if (components)

{

delete components;

}

}

private: System::Windows::Forms::ListBox^ listBox1;

protected:

private: System::Windows::Forms::ComboBox^ comboBox1;

private: System::Windows::Forms::Button^ button1;

private: System::Windows::Forms::Button^ button2;

private: System::Windows::Forms::Button^ button3;

private: System::Windows::Forms::RadioButton^ radioButton1;

private: System::Windows::Forms::RadioButton^ radioButton2;

private: System::Windows::Forms::CheckBox^ checkBox1;

private: System::Windows::Forms::TextBox^ textBox1;

private:

/// <summary>

/// Обязательная переменная конструктора.

/// </summary>

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

/// <summary>

/// Требуемый метод для поддержки конструктора — не изменяйте

/// содержимое этого метода с помощью редактора кода.

/// </summary>

void InitializeComponent(void)

{

this->listBox1 = (gcnew System::Windows::Forms::ListBox());

this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());

this->button1 = (gcnew System::Windows::Forms::Button());

this->button2 = (gcnew System::Windows::Forms::Button());

this->button3 = (gcnew System::Windows::Forms::Button());

this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());

this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());

this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());

this->textBox1 = (gcnew System::Windows::Forms::TextBox());

this->SuspendLayout();

//

// listBox1

//

this->listBox1->FormattingEnabled = true;

this->listBox1->Location = System::Drawing::Point(41, 44);

this->listBox1->Name = L"listBox1";

this->listBox1->Size = System::Drawing::Size(165, 147);

this->listBox1->TabIndex = 0;

this->listBox1->DoubleClick += gcnew System::EventHandler(this, &MyForm::ListBox1_DoubleClick);

//

// comboBox1

//

this->comboBox1->FormattingEnabled = true;

this->comboBox1->Location = System::Drawing::Point(452, 58);

this->comboBox1->Name = L"comboBox1";

this->comboBox1->Size = System::Drawing::Size(121, 21);

this->comboBox1->TabIndex = 1;

//

// button1

//

this->button1->Location = System::Drawing::Point(92, 286);

this->button1->Name = L"button1";

this->button1->Size = System::Drawing::Size(75, 23);

this->button1->TabIndex = 2;

this->button1->Text = L"add";

this->button1->UseVisualStyleBackColor = true;

this->button1->Click += gcnew System::EventHandler(this, &MyForm::Button1_Click);

//

// button2

//

this->button2->Location = System::Drawing::Point(264, 285);

this->button2->Name = L"button2";

this->button2->Size = System::Drawing::Size(75, 23);

this->button2->TabIndex = 3;

this->button2->Text = L"delete";

this->button2->UseVisualStyleBackColor = true;

this->button2->Click += gcnew System::EventHandler(this, &MyForm::Button2_Click);

//

// button3

//

this->button3->Location = System::Drawing::Point(432, 285);

this->button3->Name = L"button3";

this->button3->Size = System::Drawing::Size(75, 23);

this->button3->TabIndex = 4;

this->button3->Text = L"clear";

this->button3->UseVisualStyleBackColor = true;

this->button3->Click += gcnew System::EventHandler(this, &MyForm::Button3_Click);

//

// radioButton1

//

this->radioButton1->AutoSize = true;

this->radioButton1->Location = System::Drawing::Point(264, 61);

this->radioButton1->Name = L"radioButton1";

this->radioButton1->Size = System::Drawing::Size(78, 17);

this->radioButton1->TabIndex = 5;

this->radioButton1->TabStop = true;

this->radioButton1->Text = L"LowerCase";

this->radioButton1->UseVisualStyleBackColor = true;

//

// radioButton2

//

this->radioButton2->AutoSize = true;

this->radioButton2->Location = System::Drawing::Point(264, 101);

this->radioButton2->Name = L"radioButton2";

this->radioButton2->Size = System::Drawing::Size(78, 17);

this->radioButton2->TabIndex = 6;

this->radioButton2->TabStop = true;

this->radioButton2->Text = L"UpperCase";

this->radioButton2->UseVisualStyleBackColor = true;

//

// checkBox1

//

this->checkBox1->AutoSize = true;

this->checkBox1->Location = System::Drawing::Point(253, 173);

this->checkBox1->Name = L"checkBox1";

this->checkBox1->Size = System::Drawing::Size(95, 17);

this->checkBox1->TabIndex = 7;

this->checkBox1->Text = L"EnableButtons";

this->checkBox1->UseVisualStyleBackColor = true;

this->checkBox1->Click += gcnew System::EventHandler(this, &MyForm::CheckBox1_Click);

//

// textBox1

//

this->textBox1->Location = System::Drawing::Point(41, 231);

this->textBox1->Name = L"textBox1";

this->textBox1->Size = System::Drawing::Size(165, 20);

this->textBox1->TabIndex = 8;

//

// MyForm

//

this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);

this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

this->ClientSize = System::Drawing::Size(649, 389);

this->Controls->Add(this->textBox1);

this->Controls->Add(this->checkBox1);

this->Controls->Add(this->radioButton2);

this->Controls->Add(this->radioButton1);

this->Controls->Add(this->button3);

this->Controls->Add(this->button2);

this->Controls->Add(this->button1);

this->Controls->Add(this->comboBox1);

this->Controls->Add(this->listBox1);

this->Name = L"MyForm";

this->Text = L"MyForm";

this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);

this->ResumeLayout(false);

this->PerformLayout();

}

#pragma endregion

private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {

button1->Enabled::set(false);

button2->Enabled::set(false);

button3->Enabled::set(false);

}

private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {

String ^ s = textBox1->Text;

if(s != ""){

if (radioButton1->Checked) {

listBox1->Items->Add(s->ToLower());

}

else {

listBox1->Items->Add(s->ToUpper());

}

}

}

private: System::Void Button2_Click(System::Object^ sender, System::EventArgs^ e) {

int i = listBox1->SelectedIndex;

if (i == -1)MessageBox::Show("Ничего не выбрано");

else listBox1->Items->RemoveAt(i);

}

private: System::Void Button3_Click(System::Object^ sender, System::EventArgs^ e) {

int i = listBox1->Items->Count;

for (int k = 0; k < i; k++)listBox1->Items->RemoveAt(0);

}

private: System::Void CheckBox1_Click(System::Object^ sender, System::EventArgs^ e) {

bool chState = checkBox1->Checked::get();

if (chState) {

button1->Enabled::set(true);

button2->Enabled::set(true);

button3->Enabled::set(true);

} else {

button1->Enabled::set(false);

button2->Enabled::set(false);

button3->Enabled::set(false);

}

}

private: System::Void ListBox1_DoubleClick(System::Object^ sender, System::EventArgs^ e) {

int i = listBox1->SelectedIndex;

if (i == -1)MessageBox::Show("Ничего не выбрано");

else {

String^ s = listBox1->SelectedItem->ToString();

comboBox1->Items->Add(s);

}

}

};

}

Рисунок 2.1- Демонстрацiя роботи програми

Рисунок 2.2 - Демонстрацiя роботи програми

Рисунок 2.3 - Демонстрацiя роботи програми

ВИСНОВКИ

На лабораторній роботі було досліджено середовище програмної розробки Microsoft Visual Studio 2019 та побудовано вікно з елементами керування засобами C++/CLI на основі Windows Forms.

Програма, яка використовує в якості основної мови програмування С++/CLI, створює вікно Windows Form і має на меті використання .NET Framework, як правило розпочинається з виклику функції Main(), яка зазвичай містить активізацію деяких параметрів та команди запуску програми з формою. Основні програмні блоки знаходяться у файлі *.h.

Основою програми є вікно з елементами керування, які пов’язані між собою, оброблюють вхідні дані (у даному випадку, строки ) та виводять їх значення у вікні. Були використані такі елементи керування: ListBox, comboBox, textbox, radiobutton, checkbox.