#pragma once
namespace Lab6 {
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath();
path->AddEllipse(pictureBox2->ClientRectangle);
pictureBox2->Region = gcnew System::Drawing::Region(path);
pictureBox1->Tag = ShapeType::Rectangle;
pictureBox2->Tag = ShapeType::Ellipse;
pictureBox3->Tag = ShapeType::Square;
}
private: System::Void pictureBox2_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
dragging = true;
_oldX = e->X;
_oldY = e->Y;
}
}
private: System::Void pictureBox2_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (dragging)
{
PictureBox ^pictureBox = (PictureBox^)sender;
pictureBox->Top += e->Y - _oldY;
pictureBox->Left += e->X - _oldX;
if (label1->Bounds.Contains(pictureBox->Bounds))
{
label1->BackColor = Color::Orange;
}
else
{
label1->BackColor = Color::Wheat;
}
if (label2->Bounds.Contains(pictureBox->Bounds))
{
label2->BackColor = Color::Orange;
}
else
{
label2->BackColor = Color::Wheat;
}
}
}
private: System::Void pictureBox2_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
dragging=false;
PictureBox ^pictureBox = (PictureBox^)sender;
if (label1->Bounds.Contains(pictureBox->Bounds))
{
label3->Text = Convert::ToString(pictureBox->BackColor) + "\n" + Enum::GetName((ShapeType::typeid ), pictureBox->Tag);
}
if (label2->Bounds.Contains(pictureBox->Bounds))
{
ShapeType type = (ShapeType)pictureBox->Tag;
if (pictureBox->Tag==ShapeType::Rectangle){
pictureBox->Focus();
pictureBox->Tag = ShapeType::Ellipse;
pictureBox->Size = System::Drawing::Size(pictureBox-> Width,pictureBox->Width);
System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath();
path->AddEllipse(pictureBox->ClientRectangle);
pictureBox->Region = gcnew System::Drawing::Region(path);
}
if (pictureBox->Tag==ShapeType::Ellipse){
pictureBox->Focus();
pictureBox->Tag = ShapeType::Square;
pictureBox->Region = gcnew System::Drawing::Region(pictureBox->ClientRectangle);
}
if (pictureBox->Tag==ShapeType::Square){
pictureBox->Focus();
pictureBox->Tag = ShapeType::Rectangle;
pictureBox->Size = System::Drawing::Size(pictureBox->Width, pictureBox->Width / 2);
}
}
}
};
}