Задача 0120 (проект Windows Forms)

120. Побудувати:

а) трикутник з вершинами (100, 100), (150, 100), (80, 170);
б) прямокутник з вершинами (80, 80), (170, 80), (170, 150), (80, 150);
в) п’ятикутник з вершинами (100, 100), (150, 100), (170, 120), (150, 140), (100, 140);
г) шестикутник з вершинами (120, 100), (140, 120), (140, 140), (120, 160), (100, 140), (100, 120);
д) виконати завдання а) – г), доповнивши кожне із них вимогами замальовування побудованих плоских фігур.

public partial class Form1 : Form
    {
        private Graphics _graphics;
        private readonly Pen _pen = new Pen(Color.Black, 3);
        private readonly SolidBrush _brush = new SolidBrush(Color.BlueViolet);
        private Point[] _points;

        public Form1()
        {
            InitializeComponent();           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _points = new Point[] {new Point(100, 100), new Point(150, 100), new Point(80,  170), new Point(100, 100)};
            DrawPoly();
        }

        private void DrawPoly()
        {
            _graphics = pictureBox1.CreateGraphics();
            _graphics.Clear(Color.White);
            if (checkBox1.Checked)
                _graphics.FillPolygon(_brush, _points);
            else
                _graphics.DrawPolygon(_pen, _points);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _graphics = pictureBox1.CreateGraphics();
            _graphics.Clear(Color.White);            
            if (checkBox1.Checked)
                _graphics.FillRectangle(_brush, 80, 80, 170, 50);
            else
                _graphics.DrawRectangle(_pen, 80, 80, 170, 50);
        }

        private void button3_Click(object sender, EventArgs e)
        {            
            _points = new Point[] { new Point(100, 100), new Point(150, 100), new Point(170, 120), 
                new Point(150, 140), new Point(100, 140), new Point(100, 100)};
            DrawPoly();
        }

        private void button4_Click(object sender, EventArgs e)
        {            
            _points = new Point[] { new Point(120, 100), new Point(140, 120), new Point(140, 140), new Point(120, 160), 
                new Point(100, 140), new Point(100, 120), new Point(120, 100)};
            DrawPoly();
        }        
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s