Ejemplo n.º 1
0
        /// <summary>
        /// To save the components on a canvas and its properties to file
        /// </summary>
        public void SaveToFile(Canvas canvas)
        {
            bf = null;
            fs = null;
            if(!saved)
            { 
                saveCanvas.FileName = "UntitledCanvas.cnv";
                saveCanvas.Filter = "Canvas file(*.cnv)|*.cnv";
                DialogResult dr = saveCanvas.ShowDialog();
                Filename = saveCanvas.FileName;
                if (saveCanvas.FileName != "*.cnv")
                {

                    try
                    {

                        if (dr.ToString() == "OK")
                        {
                            fs = new FileStream(saveCanvas.FileName, FileMode.Create, FileAccess.Write);
                            bf = new BinaryFormatter();
                            bf.Serialize(fs, canvas);
                            saved = true;
                        }
                    }
                    catch (SerializationException)
                    { }

                    finally
                    {
                        if (fs != null) fs.Close();
                    }
                }
            }
            
        }
Ejemplo n.º 2
0
        public FlowNetworkSimulator()
        {
            InitializeComponent();
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            canvas = new Canvas();
            area = new Rectangle(new Point(120, 95), new Size(550, 380));
            label8.Text = "Upper flow: " + 50 + "\n" + "Lower flow: " + 50;
            if (canvas.Components.Count == 0)
            {
                flowLabel.Enabled = false;
            }
            else
            {
                flowLabel.Enabled = true;
                
            }

        }
Ejemplo n.º 3
0
        private void NewButton_Click(object sender, EventArgs e)
        {
            if (!(canvas.Components.Count() == 0))
            {
                DialogResult dr = MessageBox.Show("Do you want to save the current diagram before opening?", "Save As", MessageBoxButtons.YesNo);
                if (dr.ToString() == "Yes")
                {
                    fh.SaveToFile(canvas);

                }
                canvas = new Canvas();

                this.Refresh();
            }
            this.Refresh();
        }
Ejemplo n.º 4
0
        private void OpenButton_Click(object sender, EventArgs e)
        {
            if (canvas.Components.Count() == 0)
            {
                canvas = fh.LoadFromFile();
            }
            else
            {
                if (!fh.saved)
                {
                    DialogResult dr = MessageBox.Show("Do you want to save the current diagram before opening?",
                        "Save As", MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Yes)
                    {
                        fh.SaveToFile(canvas);
                        fh.saved = true;
                    }
                    if (dr == DialogResult.Cancel)
                    {
                        return;
                    }
                    if (dr == DialogResult.No)
                    {
                        canvas = fh.LoadFromFile();
                    }
                }

            }
            this.Refresh();
        }