Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace MyNamespace {
- using namespace System;
- using namespace System::Drawing;
- using namespace System::Windows::Forms;
- ref class MyForm : public Form
- {
- private:
- PictureBox^ pictureBox1;
- Point lastPoint;
- public:
- MyForm()
- {
- // Создание элементов управления
- pictureBox1 = gcnew PictureBox();
- pictureBox1->Dock = DockStyle::Fill;
- pictureBox1->BorderStyle = BorderStyle::FixedSingle;
- pictureBox1->Paint += gcnew PaintEventHandler(this, &MyForm::pictureBox1_Paint);
- pictureBox1->MouseDown += gcnew MouseEventHandler(this, &MyForm::pictureBox1_MouseDown);
- this->Controls->Add(pictureBox1);
- lastPoint = Point::Empty;
- }
- // Обработчик события Paint на PictureBox
- void pictureBox1_Paint(Object^ sender, PaintEventArgs^ e)
- {
- // Рисование линии между последней и текущей точкой
- if (!lastPoint.IsEmpty) {
- e->Graphics->DrawLine(Pens::Black, lastPoint, pictureBox1->PointToClient(Cursor->Position));
- }
- }
- // Обработчик события MouseDown на PictureBox
- void pictureBox1_MouseDown(Object^ sender, MouseEventArgs^ e)
- {
- // Добавление точки и перерисовка PictureBox
- lastPoint = pictureBox1->PointToClient(Cursor->Position);
- pictureBox1->Invalidate();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement