예제 #1
0
파일: Main.cs 프로젝트: Thyix/paint-winform
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpfFichiers             = new OpenFileDialog();
            OpfFichiers.Filter      = "All Files (*.*)|*.*";;
            OpfFichiers.FilterIndex = 1;
            OpfFichiers.Multiselect = false;

            if (OpfFichiers.ShowDialog() == DialogResult.OK)
            {
                string Path    = OpfFichiers.FileName;
                Dessin OpenDes = new Dessin(null, DateTime.Now, 0.0);
                if (Path[Path.Length - 1] == 't')
                {
                    //OpenDes.DrawFromTextFile(Path);
                }
                else
                {
                    OpenDes = OpenDes.Deserialize(Path);
                }
                plDessin.Refresh();
                int indice = 0;
                foreach (Point p in OpenDes.Coords)
                {
                    OpenDes.Redessiner(g, indice);
                    indice++;
                }
                indice = 0;
            }
        }
예제 #2
0
        public Dessin Deserialize(string Path)
        {
            IFormatter formatter  = new BinaryFormatter();
            Stream     filestream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read);
            Dessin     ToDes      = new Dessin(null, DateTime.Now, 0.0);

            ToDes = (Dessin)formatter.Deserialize(filestream);
            filestream.Close();
            return(ToDes);
        }
예제 #3
0
파일: Main.cs 프로젝트: Thyix/paint-winform
        public frmMain()
        {
            InitializeComponent();

            Nouveau.ShowDialog();
            this.Couleur       = Color.Black;
            this.DessinEnCours = false;
            Dess = new Dessin(Nouveau.Nom, Nouveau.Date,
                              Math.Round(r.NextDouble() * (56.78 - 12.34) + 12.34, 2));
            g = plDessin.CreateGraphics();
        }
예제 #4
0
        public void Serialize()
        {
            Dessin ToSer = new Dessin(Nom, DateCreation, Cost);

            ToSer.Coords = Coords;
            IFormatter formatter = new BinaryFormatter();
            string     Path      = string.Format("{0}.don", ToSer.Nom);
            Stream     stream    = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.None);

            formatter.Serialize(stream, ToSer);
            stream.Close();
        }
예제 #5
0
파일: Main.cs 프로젝트: Thyix/paint-winform
        private void btnNew_Click(object sender, EventArgs e)
        {
            Nouveau.ShowDialog();
            if (Nouveau.DialogResult == DialogResult.Cancel)
            {
                plDessin.Refresh();
                Dessin NewOne = new Dessin(Nouveau.Nom, Nouveau.Date, Math.Round(r.NextDouble() * (56.78 - 12.34) + 12.34, 2));
            }

            else
            {
                return;
            }
        }
예제 #6
0
        public void Save()
        {
            Dessin ToSave = new Dessin(Nom, DateCreation, Cost);

            ToSave.Coords = Coords;
            string ToFile = string.Format("{0} \r\n {1} \r\n {2} \r\n", ToSave.Nom, ToSave.DateCreation, ToSave.Cost);
            int    i      = 0;

            foreach (Point p in ToSave.Coords)
            {
                ToFile += string.Format("({0}, {1}) \r\n", ToSave.Coords[i].X, ToSave.Coords[i].Y);
                i++;
            }
            string       Path     = string.Format("{0}.txt", ToSave.Nom);
            FileStream   TextFile = new FileStream(Path, FileMode.CreateNew, FileAccess.Write, FileShare.None);
            StreamWriter s        = new StreamWriter(TextFile);

            s.Write(ToFile);
            TextFile.Close();
        }