コード例 #1
0
        //read undo
        public void Read_Json()
        {
            List_UndoLocation.Clear();

            using (FileStream fs = new FileStream("Undo_Json.json", FileMode.Open))
                using (StreamReader file = new StreamReader(fs))
                    using (JsonReader w = new JsonTextReader(file))
                    {
                        JsonSerializer  Position  = new JsonSerializer();
                        List <Position> positions = JsonConvert.DeserializeObject <List <Position> >(file.ReadToEnd());
                        //Console.WriteLine(positions[0].X);
                        //----------------------------------------------------------------------------------------
                        for (int i = 0; i <= positions.Count - 1; i++)
                        {
                            Position po         = new Position();
                            int      myTag      = positions[i].T;
                            int      Location_x = positions[i].X;
                            int      Location_y = positions[i].Y;

                            foreach (Control item in this.Controls)
                            {
                                PanelObjectHistory hx = new PanelObjectHistory(Location_x, Location_y, item);
                                if (myTag == (int)item.Tag)
                                {
                                    _undoList.Add(hx);
                                }
                            }
                        }
                    }
        }
コード例 #2
0
        public void Write_Json()
        {
            //Clear List after click button Save again
            List_UndoLocation.Clear();
            //_undoList.Clear();
            using (FileStream fs = new FileStream("Undo_Json.json", FileMode.Create))
                using (StreamWriter file = new StreamWriter(fs))
                    using (JsonWriter w = new JsonTextWriter(file))
                    {
                        JsonSerializer Position = new JsonSerializer();

                        for (int i = 0; i <= _undoList.Count - 1; i++)
                        {
                            Position po = new Position();
                            po.X = _undoList[i].x;
                            po.Y = _undoList[i].y;
                            po.T = (int)_undoList[i].targetPanel.Tag;
                            List_UndoLocation.Add(po);
                        }
                        Position.Serialize(w, List_UndoLocation);
                    }
        }