Untitled

 avatar
unknown
plain_text
a year ago
5.0 kB
6
Indexable
using System;
using System.Drawing;
using System.Windows.Forms;

namespace FigureApp
{
    public partial class Form1 : Form
    {
        private Figyra figyra;

        public Form1()
        {
            InitializeComponent();
            figyra = new Figyra();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Создание экземпляра подкласса в зависимости от выбранного типа фигуры
            if (comboBox1.SelectedItem.ToString() == "Прямоугольник")
            {
                Pryamougolnik pryamougolnik = new Pryamougolnik(figyra.X, figyra.Y, figyra.Width, figyra.Height);
                pryamougolnik.Draw(pictureBox1);
                pryamougolnik.Clear(pictureBox1);
                pryamougolnik.Move(10, 10);
            }
            else if (comboBox1.SelectedItem.ToString() == "Эллипс")
            {
                Ellipse ellipse = new Ellipse(figyra.X, figyra.Y, figyra.Width, figyra.Height);
                ellipse.Draw(pictureBox1);
                ellipse.Clear(pictureBox1);
                ellipse.Move(10, 10);
            }
            else if (comboBox1.SelectedItem.ToString() == "Многоугольник")
            {
                Mnogougolnik mnogougolnik = new Mnogougolnik(figyra.X, figyra.Y, figyra.Width, figyra.Height);
                mnogougolnik.Draw(pictureBox1);
                mnogougolnik.Clear(pictureBox1);
                mnogougolnik.Move(10, 10);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            // Обновление значения X при изменении текста в textBox1
            if (int.TryParse(textBox1.Text, out int x))
            {
                figyra.X = x;
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            // Обновление значения Y при изменении текста в textBox2
            if (int.TryParse(textBox2.Text, out int y))
            {
                figyra.Y = y;
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            // Обновление значения Width при изменении текста в textBox3
            if (int.TryParse(textBox3.Text, out int width))
            {
                figyra.Width = width;
            }
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            // Обновление значения Height при изменении текста в textBox4
            if (int.TryParse(textBox4.Text, out int height))
            {
                figyra.Height = height;
            }
        }
    }

    public class Figyra
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
    }

    public class Pryamougolnik : Figyra
    {
        public Pryamougolnik(int x, int y, int width, int height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }

        public void Draw(PictureBox pictureBox)
        {
           Graphics g = pictureBox.CreateGraphics();
           g.DrawRectangle(Pens.Black, X, Y, Width, Height);
        }

        public void Clear(PictureBox pictureBox)
        {
           Graphics g = pictureBox.CreateGraphics();
           g.Clear(Color.White);
        }

        public void Move(int dx, int dy)
        {
            X += dx;
            Y += dy;
        }
    }

    public class Ellipse : Figyra
    {
        public Ellipse(int x, int y, int width, int height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }

        public void Draw(PictureBox pictureBox)
        {
           Graphics g = pictureBox.CreateGraphics();
           g.DrawEllipse(Pens.Black, X, Y, Width, Height);
        }

        public void Clear(PictureBox pictureBox)
        {
           Graphics g = pictureBox.CreateGraphics();
           g.Clear(Color.White);
        }

        public void Move(int dx, int dy)
        {
            X += dx;
            Y += dy;
        }
    }

    public class Mnogougolnik : Figyra
    {
       public Mnogougolnik(int x, int y, int width, int height)
       {
          X = x;
          Y = y;
          Width = width;
          Height = height;
       }

       public void Draw(PictureBox pictureBox)
       {
          // Реализация отрисовки многоугольника
       }

       public void Clear(PictureBox pictureBox)
       {
          // Реализация очистки многоугольника
       }

       public void Move(int dx, int dy)
       {
          // Реализация перемещения многоугольника
       }
    }
}
Editor is loading...
Leave a Comment