Advertisement
Tark_Wight

MouseDown

Apr 23rd, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <vector>
  3.  
  4. using namespace System;
  5. using namespace System::Drawing;
  6. using namespace System::Windows::Forms;
  7.  
  8. // Класс, описывающий круг
  9. ref class Circle
  10. {
  11. public:
  12. int X;
  13. int Y;
  14. int Radius;
  15. Color Color;
  16. };
  17.  
  18. public ref class Form1 : public Form
  19. {
  20. private:
  21. Panel^ panel1;
  22. std::vector<Circle^> circles;
  23.  
  24. public:
  25. Form1()
  26. {
  27. // Создание элементов управления
  28. panel1 = gcnew Panel();
  29. panel1->Dock = DockStyle::Fill;
  30. panel1->MouseDown += gcnew MouseEventHandler(this, &Form1::panel1_MouseDown);
  31. this->Controls->Add(panel1);
  32. }
  33.  
  34. // Обработчик события MouseDown на панели
  35. void panel1_MouseDown(Object^ sender, MouseEventArgs^ e)
  36. {
  37. // Создание нового круга при щелчке на панели
  38. Circle^ circle = gcnew Circle();
  39. circle->X = e->X;
  40. circle->Y = e->Y;
  41. circle->Radius = 20;
  42. circle->Color = Color::Red;
  43.  
  44. circles.push_back(circle);
  45.  
  46. // Отображение нового круга на второй форме
  47. Form2^ form2 = gcnew Form2(circles);
  48. form2->Show();
  49. }
  50. };
  51.  
  52. public ref class Form2 : public Form
  53. {
  54. private:
  55. PictureBox^ pictureBox1;
  56. std::vector<Circle^> circles;
  57.  
  58. public:
  59. Form2(std::vector<Circle^> circles)
  60. {
  61. // Создание элементов управления
  62. this->circles = circles;
  63. pictureBox1 = gcnew PictureBox();
  64. pictureBox1->Dock = DockStyle::Fill;
  65. pictureBox1->Paint += gcnew PaintEventHandler(this, &Form2::pictureBox1_Paint);
  66. this->Controls->Add(pictureBox1);
  67. }
  68.  
  69. // Обработчик события Paint на элементе PictureBox
  70. void pictureBox1_Paint(Object^ sender, PaintEventArgs^ e)
  71. {
  72. // Рисование всех кругов из списка на элементе PictureBox
  73. for each (Circle^ circle in circles)
  74. {
  75. e->Graphics->FillEllipse(gcnew SolidBrush(circle->Color),
  76. circle->X - circle->Radius, circle->Y - circle->Radius,
  77. circle->Radius * 2, circle->Radius * 2);
  78. }
  79. }
  80. };
  81.  
  82. // Главная точка входа для приложения
  83. int main(array<System::String ^> ^args)
  84. {
  85. Application::EnableVisualStyles();
  86. Application::SetCompatibleTextRenderingDefault(false);
  87. Application::Run(gcnew Form1());
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement