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


using System;
using System.Drawing;
using System.Windows.Forms;

namespace laba5
{
    public partial class Form1 : Form
    {
        private Button btnRed, btnBlue, btnRandColor, btnPalette, btnExit, btnOK;
        private Button btnSelectImg, btnShow, btnHide;
        private Panel panel1;
        private RadioButton rbYellow, rbWhite, rbRandom;
        private GroupBox groupBoxFlags;
        private CheckBox chkTitle, chkBlue, chkExit;
        private PictureBox pictureBox1;
        private ColorDialog colorDialog1;
        private OpenFileDialog openFileDialog1;
        private Random rnd = new Random();

        public Form1()
        {
            this.Text = "Заголовок";
            this.Size = new Size(700, 450);

            btnRed = new Button { Text = "Цвет красный", Location = new Point(20, 20), Width = 130 };
            btnRed.Click += (s, e) => 
            {
                if (btnRed.BackColor == Color.Red) btnRed.BackColor = SystemColors.Control;
                else btnRed.BackColor = Color.Red;
            };

            btnBlue = new Button { Text = "Цвет окна", Location = new Point(20, 60), Width = 130 };
            btnBlue.Click += (s, e) => this.BackColor = Color.LightBlue;

            btnRandColor = new Button { Text = "Цвет из окна", Location = new Point(20, 100), Width = 130 };
            btnRandColor.Click += (s, e) => this.BackColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

            btnPalette = new Button { Text = "Цвет из палитры", Location = new Point(20, 140), Width = 130 };
            btnPalette.Click += (s, e) => { if (colorDialog1.ShowDialog() == DialogResult.OK) this.BackColor = colorDialog1.Color; };

            btnExit = new Button { Text = "Выход", Location = new Point(20, 350), Width = 130 };
            btnExit.Click += (s, e) => Application.Exit();

            panel1 = new Panel { Location = new Point(180, 20), Size = new Size(150, 130), BorderStyle = BorderStyle.FixedSingle };
            rbYellow = new RadioButton { Text = "Желтый", Location = new Point(10, 10), Checked = true };
            rbWhite = new RadioButton { Text = "Белый", Location = new Point(10, 40) };
            rbRandom = new RadioButton { Text = "Случайный", Location = new Point(10, 70) };
            panel1.Controls.AddRange(new Control[] { rbYellow, rbWhite, rbRandom });

            btnOK = new Button { Text = "OK", Location = new Point(210, 170), Width = 80 };
            btnOK.Click += (s, e) => 
            {
                if (rbYellow.Checked) this.BackColor = Color.Yellow;
                else if (rbWhite.Checked) this.BackColor = Color.White;
                else this.BackColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
            };

            pictureBox1 = new PictureBox { Location = new Point(370, 20), Size = new Size(280, 200), BorderStyle = BorderStyle.FixedSingle, SizeMode = PictureBoxSizeMode.StretchImage };

            btnSelectImg = new Button { Text = "Выбор изображения", Location = new Point(370, 240), Width = 280 };
            btnSelectImg.Click += (s, e) => 
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    pictureBox1.Image = new Bitmap(openFileDialog1.FileName);
                    pictureBox1.Visible = true;
                }
            };

            btnShow = new Button { Text = "Показать", Location = new Point(370, 280), Width = 130 };
            btnShow.Click += (s, e) => { if (pictureBox1.Image != null) pictureBox1.Visible = true; };

            btnHide = new Button { Text = "Скрыть", Location = new Point(520, 280), Width = 130 };
            btnHide.Click += (s, e) => pictureBox1.Visible = false;

            groupBoxFlags = new GroupBox { Text = "Настройки окна", Location = new Point(180, 240), Size = new Size(150, 130) };
            
            chkTitle = new CheckBox { Text = "Заголовок", Location = new Point(10, 20) };
            chkTitle.CheckedChanged += (s, e) => this.Text = chkTitle.Checked ? "Новый заголовок" : "Заголовок";

            chkBlue = new CheckBox { Text = "Цвет синий", Location = new Point(10, 50) };
            chkBlue.CheckedChanged += (s, e) => { if (chkBlue.Checked) this.BackColor = Color.Blue; };

            chkExit = new CheckBox { Text = "Выход", Location = new Point(10, 80) };
            chkExit.CheckedChanged += (s, e) => { if (chkExit.Checked) Application.Exit(); };

            groupBoxFlags.Controls.AddRange(new Control[] { chkTitle, chkBlue, chkExit });

            colorDialog1 = new ColorDialog();
            openFileDialog1 = new OpenFileDialog { Filter = "Картинки|*.jpg;*.jpeg;*.png;*.bmp" };

            this.Controls.AddRange(new Control[] { 
                btnRed, btnBlue, btnRandColor, btnPalette, btnExit, 
                panel1, btnOK, 
                pictureBox1, btnSelectImg, btnShow, btnHide, groupBoxFlags 
            });
        }
    }
}