Загрузка данных


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1
{
    public partial class Form1 : Form
    {
        // Данные для диаграммы
        private string[] regions = { "Европа", "Азия", "Африка", "Америка", "Австралия", "Антарктида" };
        private float[] values = { 11.5f, 43.4f, 30.3f, 42f, 8.7f, 14.1f };

        // Цвета для секторов
        private Color[] sliceColors = {
            Color.RoyalBlue, Color.Red, Color.ForestGreen,
            Color.Orange, Color.Purple, Color.Cyan
        };

        public Form1()
        {
            InitializeComponent();

            this.SuspendLayout();
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.ResumeLayout(false);

            this.Size = new Size(600, 450);
            this.Text = "Задание 2: Круговая диаграмма";
            this.DoubleBuffered = true;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // 1. Расчеты
            // Считаем общую сумму данных
            float totalValue = values.Sum();

            // Определяем область для рисования круга (квадрат слева)
            int chartSize = Math.Min(this.ClientSize.Width / 2, this.ClientSize.Height) - 40;
            Rectangle chartRect = new Rectangle(20, 20, chartSize, chartSize);

            // Угол начала рисования (0 градусов - это "3 часа" на циферблате)
            float startAngle = 0;

            // Шрифты для легенды
            Font legendFont = new Font("Arial", 12, FontStyle.Bold);
            Font titleFont = new Font("Arial", 14, FontStyle.Underline);

            // 2. Рисование диаграммы и легенды
            g.DrawString("Легенда:", titleFont, Brushes.Black, chartRect.Right + 40, 20);

            for (int i = 0; i < regions.Length; i++)
            {
                // Расчет угла сектора: (Значение / Сумма) * 360 градусов
                float sweepAngle = (values[i] / totalValue) * 360f;

                // Создаем кисть цвета текущего сектора
                using (SolidBrush brush = new SolidBrush(sliceColors[i]))
                {
                    // Рисуем заполненный сектор (Pie)
                    g.FillPie(brush, chartRect, startAngle, sweepAngle);

                    // Рисуем контур сектора для четкости
                    g.DrawPie(Pens.Black, chartRect, startAngle, sweepAngle);

                    // --- Рисование Легенды ---
                    int legendX = chartRect.Right + 40;
                    int legendY = 60 + (i * 30); // Смещение вниз для каждой строки

                    // Рисуем цветной квадрат перед текстом
                    g.FillRectangle(brush, legendX, legendY + 2, 16, 16);
                    g.DrawRectangle(Pens.Black, legendX, legendY + 2, 16, 16);

                    // По заданию: Цвет текста подписи такой же, как цвет части в диаграмме
                    // Мы используем ту же кисть 'brush', которой рисовали сектор
                    string legendText = $"{regions[i]} - {values[i]}";
                    g.DrawString(legendText, legendFont, brush, legendX + 25, legendY);
                }

                // Обновляем стартовый угол для следующего сектора
                startAngle += sweepAngle;
            }

            base.OnPaint(e);
        }
    }
}







using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.SuspendLayout();
            this.ClientSize = new System.Drawing.Size(384, 361);
            this.ResumeLayout(false);

            this.Size = new Size(400, 400);
            this.Text = "Задание 1: Контуры вложенных квадратов";
            this.DoubleBuffered = true;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            
            int outerSide = 180;  
            int middleSide = 120; 
            int innerSide = 60;  

            
            int centerX = this.ClientSize.Width / 2;
            int centerY = this.ClientSize.Height / 2;

            
            int xOuter = centerX - (outerSide / 2);
            int yOuter = centerY - (outerSide / 2);
            
            g.DrawRectangle(Pens.Blue, xOuter, yOuter, outerSide, outerSide);

            
            int xMiddle = centerX - (middleSide / 2);
            int yMiddle = centerY - (middleSide / 2);
            g.DrawRectangle(Pens.Red, xMiddle, yMiddle, middleSide, middleSide);

            
            int xInner = centerX - (innerSide / 2);
            int yInner = centerY - (innerSide / 2);
            g.DrawRectangle(Pens.Green, xInner, yInner, innerSide, innerSide);

            base.OnPaint(e);
        }
    }
}