Beispiel #1
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            List <FavoriteData> favoriteDataList = new List <FavoriteData>();

            // リストボックス -> オブジェクト
            for (int i = 0; i < listFavorite.Items.Count; i++)
            {
                favoriteDataList.Add((FavoriteData)(listFavorite.Items[i]));
            }

            XmlSerializer serializer = new XmlSerializer(typeof(List <FavoriteData>));

            using (StreamWriter writer = new StreamWriter(favoriteFile, false, Encoding.UTF8)) {
                serializer.Serialize(writer, favoriteDataList);
            }

            if (this.WindowState.Equals(FormWindowState.Normal))
            {
                LocationSizeData locationSizeData = new LocationSizeData();

                locationSizeData.SetTop(this.Top);
                locationSizeData.SetLeft(this.Left);
                locationSizeData.SetWidth(this.Width);
                locationSizeData.SetHeight(this.Height);

                XmlSerializer serializer_l = new XmlSerializer(typeof(LocationSizeData));
                using (StreamWriter writer = new StreamWriter(locationFile, false, Encoding.UTF8))
                {
                    serializer_l.Serialize(writer, locationSizeData);
                }
            }
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (File.Exists(favoriteFile))
            {
                XmlSerializer       serializer       = new XmlSerializer(typeof(List <FavoriteData>));
                List <FavoriteData> favoriteDataList = null;
                using (StreamReader reader = new StreamReader(favoriteFile))
                {
                    favoriteDataList = (List <FavoriteData>)serializer.Deserialize(reader);
                }

                for (int i = 0; i < favoriteDataList.Count; i++)
                {
                    listFavorite.Items.Add(favoriteDataList[i]);
                }
            }

            if (File.Exists("location.xml"))
            {
                XmlSerializer    serializer       = new XmlSerializer(typeof(LocationSizeData));
                LocationSizeData locationSizeData = null;
                using (StreamReader reader = new StreamReader(locationFile))
                {
                    locationSizeData = (LocationSizeData)serializer.Deserialize(reader);
                    this.Top         = locationSizeData.GetTop();
                    this.Left        = locationSizeData.GetLeft();
                    this.Width       = locationSizeData.GetWidth();
                    this.Height      = locationSizeData.GetHeight();
                }
            }
        }