Пример #1
0
        async void savePlayground()
        {
            var filePath = string.Empty;

#if Windows
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.InitialDirectory = "D:\\School-D\\Jaar 2 1\\Periode 3\\Design Patterns\\MonoPaint\\Saves";
                saveFileDialog.Filter           = "monoPaint files (*.mp)|";
                saveFileDialog.FilterIndex      = 2;
                saveFileDialog.RestoreDirectory = true;

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = saveFileDialog.FileName;
                }
            }
#elif OSX
            //NOTE: Nothing osx api not available!!
#endif

            if (filePath != string.Empty)
            {
                int index = filePath.LastIndexOf('.');
                if (filePath.Substring(index + 1) == "mp")
                {
                    await ShapeSerializer.Serialize(Shapes, filePath);
                }
                else
                {
                    await ShapeSerializer.Serialize(Shapes, filePath + ".mp");
                }
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var d = new SaveFileDialog())
            {
                d.FileName = "text";
                d.Filter   = "Text file|*.txt";
                if (d.ShowDialog() == DialogResult.OK)
                {
                    var shapes = listBox1.Items.OfType <Shape>().ToList();

                    using (var f = File.CreateText(d.FileName))
                    {
                        f.Write(Serializer.Serialize(shapes));
                    }
                }
            }
        }