Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <vector>
- using namespace System;
- using namespace System::Drawing;
- using namespace System::Windows::Forms;
- // Класс, описывающий круг
- ref class Circle
- {
- public:
- int X;
- int Y;
- int Radius;
- Color Color;
- };
- public ref class Form1 : public Form
- {
- private:
- Panel^ panel1;
- std::vector<Circle^> circles;
- public:
- Form1()
- {
- // Создание элементов управления
- panel1 = gcnew Panel();
- panel1->Dock = DockStyle::Fill;
- panel1->MouseDown += gcnew MouseEventHandler(this, &Form1::panel1_MouseDown);
- this->Controls->Add(panel1);
- }
- // Обработчик события MouseDown на панели
- void panel1_MouseDown(Object^ sender, MouseEventArgs^ e)
- {
- // Создание нового круга при щелчке на панели
- Circle^ circle = gcnew Circle();
- circle->X = e->X;
- circle->Y = e->Y;
- circle->Radius = 20;
- circle->Color = Color::Red;
- circles.push_back(circle);
- // Отображение нового круга на второй форме
- Form2^ form2 = gcnew Form2(circles);
- form2->Show();
- }
- };
- public ref class Form2 : public Form
- {
- private:
- PictureBox^ pictureBox1;
- std::vector<Circle^> circles;
- public:
- Form2(std::vector<Circle^> circles)
- {
- // Создание элементов управления
- this->circles = circles;
- pictureBox1 = gcnew PictureBox();
- pictureBox1->Dock = DockStyle::Fill;
- pictureBox1->Paint += gcnew PaintEventHandler(this, &Form2::pictureBox1_Paint);
- this->Controls->Add(pictureBox1);
- }
- // Обработчик события Paint на элементе PictureBox
- void pictureBox1_Paint(Object^ sender, PaintEventArgs^ e)
- {
- // Рисование всех кругов из списка на элементе PictureBox
- for each (Circle^ circle in circles)
- {
- e->Graphics->FillEllipse(gcnew SolidBrush(circle->Color),
- circle->X - circle->Radius, circle->Y - circle->Radius,
- circle->Radius * 2, circle->Radius * 2);
- }
- }
- };
- // Главная точка входа для приложения
- int main(array<System::String ^> ^args)
- {
- Application::EnableVisualStyles();
- Application::SetCompatibleTextRenderingDefault(false);
- Application::Run(gcnew Form1());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement