Save my mouse event drawing for future modification.

I used (visual studio, windows form, C #) to create some drawings.

My goal is to add a save button to save the drawing as it is, and when I open the saved file in the future, I can continue my old work ...

What happens now when I open a visual studio, I have to redraw everything.

-2
source share
1 answer

The first task is to collect the data that you draw in List<T>. For code on how to assemble them, see (All) my comments here or Reza's answer here.

PointF, :

using System.IO;
using System.Xml.Serialization;

// all drawn curve points are collected here:
List<List<PointF>> curves = new List<List<PointF>>();



private void SaveButton_Click(object sender, EventArgs e)
{

    XmlSerializer xmls = new XmlSerializer(typeof(List<List<PointF>>));
    using (Stream writer = new FileStream(yourDrawingFileName, FileMode.Create))
    {
        xmls.Serialize(writer, curves);
        writer.Close();
    }
}

private void LoadButton_Click(object sender, EventArgs e)
{
    if (File.Exists(yourDrawingFileName))
    {

        XmlSerializer xmls = new XmlSerializer(typeof(List<List<PointF>>));
        using (Stream reader = new FileStream(yourDrawingFileName, FileMode.Open))
        {
            var curves_ = xmls.Deserialize(reader);
            reader.Close();
            curves = (List<List<PointF>>) curves_;
            Console.Write(curves.Count + " curves loaded.");
        }
    }
    yourPanelOrPictureBoxOrForm.Invalidate;
}

, PointF yourClass. , ! (Points , ints strings, , Colors ..)

, draw, .

+1

All Articles