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


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

namespace lr17
{
    public partial class Form1 : Form
    {
        Bitmap bitmap;
        Graphics graphics;

        bool isDrawing = false;
        Point previousPoint;

        public Form1()
        {
            InitializeComponent();

            bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            graphics = Graphics.FromImage(bitmap);

            graphics.Clear(Color.White);

            pictureBox1.Image = bitmap;
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            isDrawing = true;
            previousPoint = e.Location;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDrawing)
            {
                graphics.DrawLine(Pens.Blue, previousPoint, e.Location);

                previousPoint = e.Location;

                pictureBox1.Invalidate();
            }
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawing = false;
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter = "PNG Image|*.png";

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                bitmap.Save(
                    saveDialog.FileName,
                    System.Drawing.Imaging.ImageFormat.Png
                );

                MessageBox.Show("Изображение сохранено!");
            }
        }
    }
}