Висновки
Програма виконує поставлені задачі: створення, збереження та редагування зображень.
Програма накладає певні обмеження : по-перше малювати можна лише на робочому полі, по-друге, зображення може бути завантажена лише з неушкодженого файлу, допускається редагування зображень, які були створенні не лише даною програмою. Після проведення серії перевірок , було встановлено, що програма працює.
Література
Борис Пахомов - C C++ и MS Visual С++ 2010 для начинающих. – СПб.: БХВ-Петербург, 2011. – 736 с.
http://msdn.microsoft.com/ru-ru/library/system.drawing(v=vs.110).aspx
http://olocoder.ru/VS19.html
http://www.helloworld.ru/texts/comp/lang/visualc/vc2/14.htm
http://www.codenet.ru/progr/visualc/mfc/mfc10.php
Додаток 1 (скріншоти роботи програми)
Рис. 1 Діалогове вікно збереження матриці в файл
Рис. 2 Режим перегляду інформації про програму
Додаток 2 (лістинг)
//==================================== MyForm.cpp ======================================
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyPaint::MyForm form;
Application::Run(%form);
return 0;
}
//==================================== MyForm.h=========================================
#pragma once
namespace MyPaint {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
using namespace System::Drawing::Imaging; // ImageFormat
/// <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;
}
}
protected:
private: System::Windows::Forms::ToolStrip^ toolStrip2;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::GroupBox^ BoxColor;
private: System::Windows::Forms::PictureBox^ pctBox_ColorShow;
private: System::Windows::Forms::PictureBox^ pctBox_Color;
private: System::Windows::Forms::Label^ Blueval;
private: System::Windows::Forms::Label^ Greenval;
private: System::Windows::Forms::Label^ Redval;
private: System::Windows::Forms::TrackBar^ Blue;
private: System::Windows::Forms::TrackBar^ Green;
private: System::Windows::Forms::TrackBar^ Red;
// кольори
private: System::Drawing::Color paintcolor; //ліній
private: System::Drawing::Color fillcolor; //заливки
private:System::Windows::Forms::DialogResult result;
private: System::Windows::Forms::PictureBox^ pctBox_ColorShow2;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::ToolStripButton^ toolStripButton1;
private: System::Windows::Forms::ToolStripButton^ toolStripButton2;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem1;
private: System::Windows::Forms::ToolStripMenuItem^ зберегтиToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ відкритиToolStripMenuItem;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private: System::Windows::Forms::ToolStripButton^ toolStripButton3;
private: System::Windows::Forms::ToolStripButton^ toolStripButton4;
private: System::Windows::Forms::ToolStripButton^ toolStripButton5;
private: System::Windows::Forms::ToolStripButton^ toolStripButton6;
private: System::Windows::Forms::ToolStripMenuItem^ довідкаToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ проПрограмуToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ проРозробникаToolStripMenuItem;
private: System::Windows::Forms::ToolStripButton^ toolStripButton7;
private: System::Windows::Forms::Label^ alphaval;
private: System::Windows::Forms::TrackBar^ alpha;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->toolStrip2 = (gcnew System::Windows::Forms::ToolStrip());
this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton2 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton3 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton4 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton5 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton7 = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripButton6 = (gcnew System::Windows::Forms::ToolStripButton());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->BoxColor = (gcnew System::Windows::Forms::GroupBox());
this->alphaval = (gcnew System::Windows::Forms::Label());
this->alpha = (gcnew System::Windows::Forms::TrackBar());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->pctBox_Color = (gcnew System::Windows::Forms::PictureBox());
this->pctBox_ColorShow2 = (gcnew System::Windows::Forms::PictureBox());
this->Blueval = (gcnew System::Windows::Forms::Label());
this->Greenval = (gcnew System::Windows::Forms::Label());
this->Redval = (gcnew System::Windows::Forms::Label());
this->Blue = (gcnew System::Windows::Forms::TrackBar());
this->Green = (gcnew System::Windows::Forms::TrackBar());
this->Red = (gcnew System::Windows::Forms::TrackBar());
this->pctBox_ColorShow = (gcnew System::Windows::Forms::PictureBox());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->toolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->зберегтиToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->відкритиToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->довідкаToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->проПрограмуToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->проРозробникаToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
this->toolStrip2->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->BoxColor->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->alpha))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_Color))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_ColorShow2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Blue))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Green))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Red))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_ColorShow))->BeginInit();
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// toolStrip2
//
this->toolStrip2->BackColor = System::Drawing::Color::WhiteSmoke;
this->toolStrip2->Dock = System::Windows::Forms::DockStyle::Left;
this->toolStrip2->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(7) {this->toolStripButton1,
this->toolStripButton2, this->toolStripButton3, this->toolStripButton4, this->toolStripButton5, this->toolStripButton7, this->toolStripButton6});
this->toolStrip2->Location = System::Drawing::Point(0, 24);
this->toolStrip2->Name = L"toolStrip2";
this->toolStrip2->Size = System::Drawing::Size(24, 491);
this->toolStrip2->TabIndex = 1;
this->toolStrip2->Text = L"toolStrip2";
//
// toolStripButton1
//
this->toolStripButton1->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton1.Image")));
this->toolStripButton1->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton1->Name = L"toolStripButton1";
this->toolStripButton1->Size = System::Drawing::Size(21, 20);
this->toolStripButton1->Text = L"Прямокутник";
this->toolStripButton1->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton1_Click_1);
//
// toolStripButton2
//
this->toolStripButton2->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton2.Image")));
this->toolStripButton2->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton2->Name = L"toolStripButton2";
this->toolStripButton2->Size = System::Drawing::Size(21, 20);
this->toolStripButton2->Text = L"Еліпс";
this->toolStripButton2->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton2_Click);
//
// toolStripButton3
//
this->toolStripButton3->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
this->toolStripButton3->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton3->Font = (gcnew System::Drawing::Font(L"Segoe UI", 8));
this->toolStripButton3->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton3.Image")));
this->toolStripButton3->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton3->Name = L"toolStripButton3";
this->toolStripButton3->Size = System::Drawing::Size(21, 20);
this->toolStripButton3->Text = L"Пряма лінія";
this->toolStripButton3->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton3_Click);
//
// toolStripButton4
//
this->toolStripButton4->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton4->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton4.Image")));
this->toolStripButton4->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton4->Name = L"toolStripButton4";
this->toolStripButton4->Size = System::Drawing::Size(21, 20);
this->toolStripButton4->Text = L"Стрілка";
this->toolStripButton4->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton4_Click);
//
// toolStripButton5
//
this->toolStripButton5->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton5->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton5.Image")));
this->toolStripButton5->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton5->Name = L"toolStripButton5";
this->toolStripButton5->Size = System::Drawing::Size(21, 20);
this->toolStripButton5->Text = L"Ромб";
this->toolStripButton5->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton5_Click);
//
// toolStripButton7
//
this->toolStripButton7->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton7->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton7.Image")));
this->toolStripButton7->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton7->Name = L"toolStripButton7";
this->toolStripButton7->Size = System::Drawing::Size(21, 20);
this->toolStripButton7->Text = L"Трикутник";
this->toolStripButton7->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton7_Click);
//
// toolStripButton6
//
this->toolStripButton6->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton6->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton6.Image")));
this->toolStripButton6->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton6->Name = L"toolStripButton6";
this->toolStripButton6->Size = System::Drawing::Size(21, 20);
this->toolStripButton6->Text = L"Гумка";
this->toolStripButton6->Click += gcnew System::EventHandler(this, &MyForm::toolStripButton6_Click);
//
// pictureBox1
//
this->pictureBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->pictureBox1->BackColor = System::Drawing::Color::White;
this->pictureBox1->Location = System::Drawing::Point(29, 24);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(710, 479);
this->pictureBox1->TabIndex = 2;
this->pictureBox1->TabStop = false;
this->pictureBox1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox1_MouseDown);
this->pictureBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox1_MouseMove);
this->pictureBox1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox1_MouseUp);
//
// BoxColor
//
this->BoxColor->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Right));
this->BoxColor->BackColor = System::Drawing::Color::WhiteSmoke;
this->BoxColor->Controls->Add(this->alphaval);
this->BoxColor->Controls->Add(this->alpha);
this->BoxColor->Controls->Add(this->radioButton2);
this->BoxColor->Controls->Add(this->radioButton1);
this->BoxColor->Controls->Add(this->pctBox_Color);
this->BoxColor->Controls->Add(this->pctBox_ColorShow2);
this->BoxColor->Controls->Add(this->Blueval);
this->BoxColor->Controls->Add(this->Greenval);
this->BoxColor->Controls->Add(this->Redval);
this->BoxColor->Controls->Add(this->Blue);
this->BoxColor->Controls->Add(this->Green);
this->BoxColor->Controls->Add(this->Red);
this->BoxColor->Controls->Add(this->pctBox_ColorShow);
this->BoxColor->ForeColor = System::Drawing::SystemColors::Control;
this->BoxColor->Location = System::Drawing::Point(737, 25);
this->BoxColor->Name = L"BoxColor";
this->BoxColor->Size = System::Drawing::Size(215, 490);
this->BoxColor->TabIndex = 3;
this->BoxColor->TabStop = false;
//
// alphaval
//
this->alphaval->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->alphaval->AutoSize = true;
this->alphaval->BackColor = System::Drawing::Color::WhiteSmoke;
this->alphaval->ForeColor = System::Drawing::SystemColors::ControlText;
this->alphaval->Location = System::Drawing::Point(3, 385);
this->alphaval->Name = L"alphaval";
this->alphaval->Size = System::Drawing::Size(14, 13);
this->alphaval->TabIndex = 14;
this->alphaval->Text = L"A";
//
// alpha
//
this->alpha->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->alpha->Location = System::Drawing::Point(50, 385);
this->alpha->Maximum = 255;
this->alpha->Name = L"alpha";
this->alpha->Size = System::Drawing::Size(154, 45);
this->alpha->TabIndex = 5;
this->alpha->Scroll += gcnew System::EventHandler(this, &MyForm::alpha_Scroll);
//
// radioButton2
//
this->radioButton2->AutoSize = true;
this->radioButton2->ForeColor = System::Drawing::SystemColors::ControlText;
this->radioButton2->Location = System::Drawing::Point(99, 23);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(68, 17);
this->radioButton2->TabIndex = 12;
this->radioButton2->Text = L"Заливка";
this->radioButton2->UseVisualStyleBackColor = true;
this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &MyForm::radioButton2_CheckedChanged);
//
// radioButton1
//
this->radioButton1->AutoSize = true;
this->radioButton1->Checked = true;
this->radioButton1->ForeColor = System::Drawing::SystemColors::ControlText;
this->radioButton1->Location = System::Drawing::Point(8, 23);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(60, 17);
this->radioButton1->TabIndex = 11;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"Контур";
this->radioButton1->UseVisualStyleBackColor = true;
this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &MyForm::radioButton1_CheckedChanged);
//
// pctBox_Color
//
this->pctBox_Color->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->pctBox_Color->Cursor = System::Windows::Forms::Cursors::Cross;
this->pctBox_Color->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pctBox_Color.Image")));
this->pctBox_Color->Location = System::Drawing::Point(78, 85);
this->pctBox_Color->Name = L"pctBox_Color";
this->pctBox_Color->Size = System::Drawing::Size(126, 126);
this->pctBox_Color->SizeMode = System::Windows::Forms::PictureBoxSizeMode::AutoSize;
this->pctBox_Color->TabIndex = 1;
this->pctBox_Color->TabStop = false;
this->pctBox_Color->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox_Color_MouseDown);
this->pctBox_Color->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox_Color_MouseMove);
this->pctBox_Color->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::pctBox_Color_MouseUp);
//
// pctBox_ColorShow2
//
this->pctBox_ColorShow2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->pctBox_ColorShow2->Location = System::Drawing::Point(8, 103);
this->pctBox_ColorShow2->Name = L"pctBox_ColorShow2";
this->pctBox_ColorShow2->Size = System::Drawing::Size(41, 41);
this->pctBox_ColorShow2->TabIndex = 9;
this->pctBox_ColorShow2->TabStop = false;
//
// Blueval
//
this->Blueval->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Blueval->AutoSize = true;
this->Blueval->BackColor = System::Drawing::Color::White;
this->Blueval->Cursor = System::Windows::Forms::Cursors::Default;
this->Blueval->ForeColor = System::Drawing::SystemColors::ControlText;
this->Blueval->Location = System::Drawing::Point(3, 345);
this->Blueval->Name = L"Blueval";
this->Blueval->Size = System::Drawing::Size(14, 13);
this->Blueval->TabIndex = 8;
this->Blueval->Text = L"B";
//
// Greenval
//
this->Greenval->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Greenval->AutoSize = true;
this->Greenval->ForeColor = System::Drawing::SystemColors::ControlText;
this->Greenval->Location = System::Drawing::Point(3, 302);
this->Greenval->Name = L"Greenval";
this->Greenval->Size = System::Drawing::Size(15, 13);
this->Greenval->TabIndex = 7;
this->Greenval->Text = L"G";
//
// Redval
//
this->Redval->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Redval->AutoSize = true;
this->Redval->ForeColor = System::Drawing::SystemColors::ControlText;
this->Redval->Location = System::Drawing::Point(3, 256);
this->Redval->Name = L"Redval";
this->Redval->Size = System::Drawing::Size(15, 13);
this->Redval->TabIndex = 6;
this->Redval->Text = L"R";
//
// Blue
//
this->Blue->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Blue->Cursor = System::Windows::Forms::Cursors::Hand;
this->Blue->Location = System::Drawing::Point(50, 345);
this->Blue->Maximum = 255;
this->Blue->Name = L"Blue";
this->Blue->Size = System::Drawing::Size(154, 45);
this->Blue->TabIndex = 5;
this->Blue->Scroll += gcnew System::EventHandler(this, &MyForm::Blue_Sroll);
//
// Green
//
this->Green->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Green->Cursor = System::Windows::Forms::Cursors::Hand;
this->Green->Location = System::Drawing::Point(50, 302);
this->Green->Maximum = 255;
this->Green->Name = L"Green";
this->Green->Size = System::Drawing::Size(154, 45);
this->Green->TabIndex = 4;
this->Green->Scroll += gcnew System::EventHandler(this, &MyForm::Green_scroll);
//
// Red
//
this->Red->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->Red->Cursor = System::Windows::Forms::Cursors::Hand;
this->Red->Location = System::Drawing::Point(50, 256);
this->Red->Maximum = 255;
this->Red->Name = L"Red";
this->Red->Size = System::Drawing::Size(154, 45);
this->Red->TabIndex = 3;
this->Red->Scroll += gcnew System::EventHandler(this, &MyForm::Red_Scroll);
//
// pctBox_ColorShow
//
this->pctBox_ColorShow->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->pctBox_ColorShow->Location = System::Drawing::Point(8, 172);
this->pctBox_ColorShow->Name = L"pctBox_ColorShow";
this->pctBox_ColorShow->Size = System::Drawing::Size(41, 39);
this->pctBox_ColorShow->TabIndex = 2;
this->pctBox_ColorShow->TabStop = false;
//
// menuStrip1
//
this->menuStrip1->BackColor = System::Drawing::Color::WhiteSmoke;
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->toolStripMenuItem1,
this->довідкаToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(953, 24);
this->menuStrip1->TabIndex = 4;
this->menuStrip1->Text = L"menuStrip1";
//
// toolStripMenuItem1
//
this->toolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->зберегтиToolStripMenuItem,
this->відкритиToolStripMenuItem});
this->toolStripMenuItem1->Name = L"toolStripMenuItem1";
this->toolStripMenuItem1->Size = System::Drawing::Size(48, 20);
this->toolStripMenuItem1->Text = L"Файл";
//
// зберегтиToolStripMenuItem
//
this->зберегтиToolStripMenuItem->Name = L"зберегтиToolStripMenuItem";
this->зберегтиToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->зберегтиToolStripMenuItem->Text = L"Зберегти";
this->зберегтиToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::saveImage);
//
// відкритиToolStripMenuItem
//
this->відкритиToolStripMenuItem->Name = L"відкритиToolStripMenuItem";
this->відкритиToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->відкритиToolStripMenuItem->Text = L"Відкрити";
this->відкритиToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::openImage);
//
// довідкаToolStripMenuItem
//
this->довідкаToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->проПрограмуToolStripMenuItem,
this->проРозробникаToolStripMenuItem});
this->довідкаToolStripMenuItem->Name = L"довідкаToolStripMenuItem";
this->довідкаToolStripMenuItem->Size = System::Drawing::Size(61, 20);
this->довідкаToolStripMenuItem->Text = L"Довідка";
//
// проПрограмуToolStripMenuItem
//
this->проПрограмуToolStripMenuItem->Name = L"проПрограмуToolStripMenuItem";
this->проПрограмуToolStripMenuItem->Size = System::Drawing::Size(166, 22);
this->проПрограмуToolStripMenuItem->Text = L"Про програму";
this->проПрограмуToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::AboutProgram);
//
// проРозробникаToolStripMenuItem
//
this->проРозробникаToolStripMenuItem->Name = L"проРозробникаToolStripMenuItem";
this->проРозробникаToolStripMenuItem->Size = System::Drawing::Size(166, 22);
this->проРозробникаToolStripMenuItem->Text = L"Про розробника";
this->проРозробникаToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::AboutMe);
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(953, 515);
this->Controls->Add(this->BoxColor);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->toolStrip2);
this->Controls->Add(this->menuStrip1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->MainMenuStrip = this->menuStrip1;
this->Name = L"MyForm";
this->RightToLeft = System::Windows::Forms::RightToLeft::No;
this->Text = L"MyPaint";
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &MyForm::MyForm_Closing);
this->toolStrip2->ResumeLayout(false);
this->toolStrip2->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->BoxColor->ResumeLayout(false);
this->BoxColor->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->alpha))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_Color))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_ColorShow2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Blue))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Green))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Red))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pctBox_ColorShow))->EndInit();
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
public: enum class Item {Ellipse, Rectangle, Line,Arrow,Rhomb,Triangle, eraser};
Item currItem;
bool choose;
bool Color_Line;
bool paint;
bool select;
Rectangle myRectangle;
int x,y,lx,ly;
Point startPoint,endPoint;
#pragma endregion
private: System::Void pctBox_Color_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
choose=true;
}
private: System::Void pctBox_Color_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
choose=false;
}
// вибір кольору
private: System::Void pctBox_Color_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
try
{
if (choose)
{
Bitmap^ bmp = gcnew Bitmap(pctBox_Color->Image);
if (Color_Line)
{
select=true;
fillcolor = bmp->GetPixel(e->X, e->Y);
Red->Value = fillcolor.R;
Blue->Value = fillcolor.B;
Green->Value = fillcolor.G;
alpha->Value = fillcolor.A;
Redval->Text = "R = " + fillcolor.R.ToString();
Blueval->Text = "B = " + fillcolor.B.ToString();
Greenval->Text = "G = " + fillcolor.G.ToString();
alphaval->Text = "A = " + fillcolor.A.ToString();
}
else
{
select=true;
paintcolor = bmp->GetPixel(e->X, e->Y);
Red->Value = paintcolor.R;
Blue->Value = paintcolor.B;
Green->Value = paintcolor.G;
alpha->Value = paintcolor.A;
Redval->Text = "R = " + paintcolor.R.ToString();
Blueval->Text = "B = " + paintcolor.B.ToString();
Greenval->Text = "G = " + paintcolor.G.ToString();
alphaval->Text = "A = " + paintcolor.A.ToString();
}
(Color_Line)?(pctBox_ColorShow2->BackColor=fillcolor):(pctBox_ColorShow->BackColor=paintcolor);
}
}
catch (ArgumentOutOfRangeException^)
{
choose = false;
MessageBox:: Show (L"Ви вийшли за задану область ",L"Помилка",MessageBoxButtons::OK,MessageBoxIcon::Error);
}
}
// корекція червоного
private: System::Void Red_Scroll(System::Object^ sender, System::EventArgs^ e) {
if (Color_Line)
{
fillcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow2->BackColor=fillcolor;
Redval->Text="R: " + fillcolor.R.ToString();
}
else
{
paintcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow->BackColor=paintcolor;
Redval->Text="R: " + paintcolor.R.ToString();
}
}
// корекція зеленого
private: System::Void Green_scroll(System::Object^ sender, System::EventArgs^ e) {
if (Color_Line)
{
fillcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow2->BackColor=fillcolor;
Greenval->Text="G: " + fillcolor.G.ToString();
}
else
{
paintcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow->BackColor=paintcolor;
Greenval->Text="G: " + paintcolor.G.ToString();
}
}
// корекція синього
private: System::Void Blue_Sroll(System::Object^ sender, System::EventArgs^ e) {
if (Color_Line)
{
fillcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow2->BackColor=fillcolor;
Blueval->Text="B: " + fillcolor.B.ToString();
}
else
{
paintcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow->BackColor=paintcolor;
Blueval->Text="B: " + paintcolor.B.ToString();
}
}
// корекція прозорості
private: System::Void alpha_Scroll(System::Object^ sender, System::EventArgs^ e) {
if (Color_Line)
{
fillcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow2->BackColor=fillcolor;
alphaval->Text="A: " + fillcolor.A.ToString();
}
else
{
paintcolor=Color::FromArgb(alpha->Value,Red->Value,Green->Value,Blue->Value);
pctBox_ColorShow->BackColor=paintcolor;
alphaval->Text="A: " + paintcolor.A.ToString();
}
}
// вибір кольору заливки чи ліній
private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
Color_Line=false;
}
private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
Color_Line=true;
}
// ----------------------------------------------------------------
// вибір фігури
private: System::Void toolStripButton1_Click_1(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Rectangle;
}
private: System::Void toolStripButton2_Click(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Ellipse;
}
private: System::Void toolStripButton3_Click(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Line;
}
private: System::Void toolStripButton4_Click(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Arrow;
}
private: System::Void toolStripButton5_Click(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Rhomb;
}
private: System::Void toolStripButton7_Click(System::Object^ sender, System::EventArgs^ e) {
currItem=Item::Triangle;
}
private: System::Void toolStripButton6_Click(System::Object^ sender, System::EventArgs^ e) {
currItem = Item::eraser;
}
// ------------------------------------------------------------------
// малювання фігур
private: System::Void pctBox1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (paint)
{
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor)); // створення нового пера для малювання
Graphics^ g = pictureBox1->CreateGraphics(); // створенння об*єкту малювання
if (currItem==Item::Arrow || currItem==Item::Rectangle || currItem==Item::Ellipse || currItem==Item::Rhomb || currItem==Item::Triangle)
{
ControlPaint::DrawReversibleFrame(myRectangle, this->BackColor, FrameStyle::Dashed);
Point endPoint = this->PointToScreen(Point(e->X, e->Y));
int width = endPoint.X - startPoint.X;
int height = endPoint.Y - startPoint.Y;
myRectangle = Rectangle(startPoint.X, startPoint.Y, width + pictureBox1->Left, height + pictureBox1->Top);//38,49
ControlPaint::DrawReversibleFrame(myRectangle, this->BackColor, FrameStyle::Dashed);
Control::Invalidate();
}
else if (currItem==Item::Line)
{
ControlPaint::DrawReversibleLine(startPoint, endPoint, SystemColors::Control);
endPoint = this->PointToScreen(Point(e->X + pictureBox1->Left, e->Y + pictureBox1->Top));
ControlPaint::DrawReversibleLine(startPoint, endPoint, SystemColors::Control);
Control::Invalidate();
}
else if (currItem==Item::eraser)
{
g->FillEllipse(gcnew SolidBrush(pictureBox1->BackColor), e->X-x/25 , e->Y-y/25 , 100, 100);
}
}
}
private: System::Void pctBox1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (!select)
paintcolor=Color::FromArgb(255,0,0,0); // чорний колір за заамовчуванням
Control::Invalidate();
paint = true;
x = e->X;
y = e->Y;
{
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
paint = true;
}
Control^ control = dynamic_cast<Control^>(sender);
startPoint = control->PointToScreen(Point(e->X, e->Y));
endPoint = startPoint;
lx=x;
ly=y;
}
}
private: System::Void pctBox1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
paint = false;
lx = e->X;
ly = e->Y;
// прямокутник
if (currItem == Item::Rectangle && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Rectangle controlRectangle;
for (int i = 0; i < Controls->Count; i++)
{
controlRectangle = Controls[i]->RectangleToScreen(Controls[i]->ClientRectangle);
}
myRectangle = Rectangle(0, 0, 0, 0);
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Brush^fill_color=gcnew SolidBrush(fillcolor); // заливка
Graphics^ g = pictureBox1->CreateGraphics();
if (x > lx && y < ly)
{
g->DrawRectangle(pen_color, (lx), (y), (x - lx), (ly - y));
g->FillRectangle(fill_color, (lx), (y), (x - lx), (ly - y));
}
else if (x < lx && y > ly)
{
g->
DrawRectangle(pen_color, (x), (ly), (lx - x), (y - ly));
g->FillRectangle(fill_color,(x), (ly), (lx - x), (y - ly));
}
else if (x > lx && y > ly)
{
g->DrawRectangle(pen_color, (lx), (ly), (x - lx), (y - ly));
g->FillRectangle(fill_color, (lx), (ly), (x - lx), (y - ly));
}
else
{
g->DrawRectangle(pen_color, (x), (y), (lx - x), (ly - y));
g->FillRectangle(fill_color, (x), (y), (lx - x), (ly - y));
}
delete g;
}
// еліпс
else if (currItem == Item::Ellipse && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Rectangle controlRectangle;
for (int i = 0; i < Controls->Count; i++)
{
controlRectangle = Controls[i]->RectangleToScreen(Controls[i]->ClientRectangle);
}
myRectangle = Rectangle(0, 0, 0, 0);
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Brush^fill_color=gcnew SolidBrush(fillcolor); // заливка
Graphics^ g = pictureBox1->CreateGraphics();
if (x > lx && y < ly)
{
g->DrawEllipse(pen_color, (lx), (y), (x - lx), (ly - y));
g->FillEllipse(fill_color,(lx), (y), (x - lx), (ly - y));
}
else if (x < lx && y > ly)
{
g->DrawEllipse(pen_color, (x), (ly), (lx - x), (y - ly));
g->FillEllipse(fill_color,(x), (ly), (lx - x), (y - ly));
}
else if (x > lx && y > ly)
{
g->DrawEllipse(pen_color, (lx), (ly), (x - lx), (y - ly));
g->FillEllipse(fill_color,(lx), (ly), (x - lx), (y - ly));
}
else
{
g->DrawEllipse(pen_color, (x), (y), (lx - x), (ly - y));
g->FillEllipse(fill_color,(x), (y), (lx - x), (ly - y));
}
delete g;
}
// лінія
else if (currItem == Item::Line && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Graphics^ g = pictureBox1->CreateGraphics();
g->DrawLine(pen_color,(x),(y),(lx),(ly));
delete g;
}
// стрілка
else if (currItem == Item::Arrow && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Graphics^ g = pictureBox1->CreateGraphics();
if (x<lx)
{
g->DrawLine(pen_color,(x),(y+ly)/2,(lx),(y+ly)/2);
g->DrawLine(pen_color,(lx),(y+ly)/2,((lx-(lx-x)/10)),(y));
g->DrawLine(pen_color,(lx),(y+ly)/2,((lx-(lx-x)/10)),(ly));
}
else if (x>lx)
{
g->DrawLine(pen_color,(x),(y+ly)/2,(lx),(y+ly)/2);
g->DrawLine(pen_color,(lx),(y+ly)/2,(lx+((lx+x)/10)),(y));
g->DrawLine(pen_color,(lx),(y+ly)/2,(lx+((lx+x)/10)),(ly));
}
delete g;
}
// ромб
else if (currItem == Item::Rhomb && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Brush^fill_color=gcnew SolidBrush(fillcolor); // заливка
Graphics^ g = pictureBox1->CreateGraphics();
Point point1,point2,point3,point4;
point1.X=x;
point1.Y=(y+ly)/2;
point2.X=(x+lx)/2;
point2.Y=y;
point3.X=lx;
point3.Y=(ly+y)/2;
point4.X=(x+lx)/2;
point4.Y=ly;
array <Point>^ points = {point1, point2, point3, point4 } ;
g->DrawPolygon(pen_color,points);
g->FillPolygon(fill_color,points);
delete g;
}
else if (currItem == Item::Triangle && e->Button == System::Windows::Forms::MouseButtons::Left)
{
Pen^ pen_color = gcnew Pen(gcnew SolidBrush(paintcolor));
Brush^fill_color=gcnew SolidBrush(fillcolor); // заливка
Graphics^ g = pictureBox1->CreateGraphics();
Point point1,point2,point3;
point1=Point(x,ly);
point2=Point((x+lx)/2,y);
point3=Point(lx,ly);
array <Point>^ points1 = {point1, point2, point3 };
g->DrawPolygon(pen_color, points1);
g->FillPolygon(fill_color,points1);
delete g;
}
}
private: System::Void openImage(System::Object^ sender, System::EventArgs^ e) {
Stream^ myStream;
// Displays an OpenFileDialog so the user can select a Cursor.
OpenFileDialog^ open_image1 = gcnew OpenFileDialog; //Відкривається діалогове вікно для відкриття зображення
open_image1->InitialDirectory = "c:\\"; //Встановлюється початкова папка
open_image1->Filter = "JPEG(*.JPG;*.JPEG;*.JPE)|*.JPG;*.JPEG;*.JPE|Bitmap(*.BMP)|*.bmp|GIF(*.gif)|*.gif|Png(*.png)|*.png|Icon(*.Icon)|*.Icon|All files(*.*) |*.JPG;*.JPEG;*.JPE;*.bmp;*.gif;*.png;*.Icon"; //Формат файлів, котрі можна відкрити
open_image1->FilterIndex = 6;
open_image1->Multiselect = true;
open_image1->Title = "Оберіть зображення";
if (open_image1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
try{
if ((myStream = open_image1->OpenFile()) != nullptr)
{
Bitmap^ bitmap2 = gcnew Bitmap(myStream);
pictureBox1->Image = bitmap2;
if (pictureBox1->Image->Height <= pictureBox1->Height && pictureBox1->Image->Width <= pictureBox1->Width)
{
pictureBox1->Visible = true;
pictureBox1->SizeMode = PictureBoxSizeMode::CenterImage;
MessageBox::Show(L"Зображення успішно завантажене", L"Повідомлення",MessageBoxButtons::OK,
MessageBoxIcon::Information);
}
myStream->Close();
}
}
catch (ArgumentException^)
{
MessageBox::Show(L"Неможливо зчитати файл з диску.", L"Помилка",MessageBoxButtons::OK,MessageBoxIcon::Error);
}
}
}
private: System::Void saveImage(System::Object^ sender, System::EventArgs^ e) {
Bitmap^ bmp = gcnew Bitmap(pictureBox1->Width, pictureBox1->Height);
Graphics^ g = Graphics::FromImage(bmp);
Rectangle rect = pictureBox1->RectangleToScreen(pictureBox1->ClientRectangle);
g->CopyFromScreen(rect.Location, Point::Empty, pictureBox1->Size);
delete g;
SaveFileDialog ^ save_image = gcnew SaveFileDialog();
save_image->Filter = "JPEG(*.JPG;*.JPEG;*.JPE)|*.JPG;*.JPEG;*.JPE|Bitmap(*.BMP)|*.bmp|GIF(*.gif)|*.gif|Png(*.png)|*.png|Icon(*.Icon)|*.Icon";
// Show the Dialog.
// If the user clicked OK in the dialog and
// a .CUR file was selected, open it.
if (save_image->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
try{
{
if (File::Exists(save_image->FileName))
{
File::Delete(save_image->FileName);
}
switch (save_image->FilterIndex)
{
case 1:
bmp->Save(save_image->FileName, ImageFormat::Jpeg);
break;
case 2:
bmp->Save(save_image->FileName, ImageFormat::Bmp);
break;
case 3:
bmp->Save(save_image->FileName, ImageFormat::Gif);
break;
case 4:
bmp->Save(save_image->FileName, ImageFormat::Png);
break;
case 5:
bmp->Save(save_image->FileName, ImageFormat::Icon);
break;
default:
break;
}
}
}
catch (ArgumentException^)
{
MessageBox::Show(L"Неможливо зберегти файл",L"Помилка",MessageBoxButtons::OK, MessageBoxIcon::Error);
}
}
}
private: System::Void MyForm_Closing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if (( MessageBox::Show(L" Ви бажаєте вийти з програми?"+"\n " + "Всі незбережені дані будуть втрачені",
L"Закриття програми",MessageBoxButtons::YesNo,MessageBoxIcon::Question) == ::System::Windows::Forms::DialogResult::No))
e->Cancel=true;
else
e->Cancel=false;
}
private: System::Void AboutProgram(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show(L"MyPaint 1.0"+"\n\n\n"+L"Дана програма призначена для відкриття," +
L"створення, редагування та збереження малюнків"+"\n"+ L"Дана програма є вільним програмним забезпеченням",L"Про програму");
}
private: System::Void AboutMe(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show(L"Генча Максим "+"\n\n"+L"Студент групи ІК-31, ФІОТ,НТУУ “КПІ” "+ "\n\n" + "Email: cool.mr.maksim@gmail.com"+"\n\n\n\t"+" 2014",
L"Розробник", MessageBoxButtons::OK);
}
};
}