Exemple #1
0
        private void buttonLoadFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog myOpenFileDialog = new OpenFileDialog();

            myOpenFileDialog.Title            = "Load File of Objects";
            myOpenFileDialog.CheckFileExists  = true;
            myOpenFileDialog.CheckPathExists  = true;
            myOpenFileDialog.DefaultExt       = "shp";
            myOpenFileDialog.Filter           = "Shape files (*.shp)|*.shp";
            myOpenFileDialog.FilterIndex      = 1;
            myOpenFileDialog.RestoreDirectory = true;
            if (myOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fInput = myOpenFileDialog.FileName;
                using (var reader = new System.IO.StreamReader(fInput))
                {
                    SerializationObject serializationObject = new SerializationObject(nLayer, myLayers, curLayer);

                    var serializer = new XmlSerializer(serializationObject.GetType());
                    serializationObject = (SerializationObject)serializer.Deserialize(reader);
                    reader.Close();

                    nLayer = serializationObject.nLayer;
                    for (int i = 0; i < nLayer; ++i)
                    {
                        myLayers[i] = serializationObject.myLayers[i];
                    }
                    curLayer = serializationObject.curLayer;
                    RefreshGraphics();
                    nPoint = 0;
                }
            }
        }
Exemple #2
0
        private void buttonSaveFile_Click(object sender, EventArgs e)
        {
            SaveFileDialog mySaveFileDialog = new SaveFileDialog();

            mySaveFileDialog.Title            = "Save File of Objects";
            mySaveFileDialog.CheckPathExists  = true;
            mySaveFileDialog.DefaultExt       = "shp";
            mySaveFileDialog.Filter           = "Shape files (*.shp)|*.shp|All files (*.*)|*.*";
            mySaveFileDialog.FilterIndex      = 1;
            mySaveFileDialog.RestoreDirectory = true;
            if (mySaveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fOutput = mySaveFileDialog.FileName;
                using (var writer = new System.IO.StreamWriter(fOutput))
                {
                    SerializationObject serializationObject = new SerializationObject(nLayer, myLayers, curLayer);

                    var serializer = new XmlSerializer(serializationObject.GetType());
                    serializer.Serialize(writer, serializationObject);
                    writer.Flush();
                }
            }
        }