Beispiel #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog
            {
                Filter = @"Binary format (*.dat)|*.dat|CSV format (*.csv)|*.csv|XML format (*.xml)|*.xml|" +
                         @"JSON format (*.json)|*.json|YAML format (*.yaml)|*.yaml"
            };

            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            var balls = new List <Ball>();

            foreach (var ball in pctbx_canvas.Controls)
            {
                if (ball is Ball)
                {
                    balls.Add(ball as Ball);
                }
            }

            var memento = new PctbxMemento(balls);

            memento.SaveState(saveFileDialog.FileName);
        }
Beispiel #2
0
        private void btn_load_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                Filter = @"Binary format (*.dat)|*.dat|CSV format (*.csv)|*.csv|XML format (*.xml)|*.xml|" +
                         @"JSON format (*.json)|*.json|YAML format (*.yaml)|*.yaml"
            };

            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            try
            {
                var balls = PctbxMemento.RestoreState(openFileDialog.FileName);

                foreach (var ball in balls)
                {
                    ball.SetPctbx(pctbx_canvas);
                    var thread = new Thread(ball.MoveBall);
                    thread.Start();
                }
            }
            catch (Exception)
            {
                MessageBox.Show(@"There is no saved data!!!", @"Balls", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #3
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog
            {
                Filter = @"Binary format (*.dat)|*.dat|CSV format (*.csv)|*.csv|XML format (*.xml)|*.xml|" +
                         @"JSON format (*.json)|*.json|YAML format (*.yaml)|*.yaml"
            };
            if (saveFileDialog.ShowDialog() == DialogResult.Cancel) return;

            var balls = new List<Ball>();
            foreach (var ball in pctbx_canvas.Controls)
            {
                if (ball is Ball)
                {
                    balls.Add(ball as Ball);
                }
            }

            var memento = new PctbxMemento(balls);
            memento.SaveState(saveFileDialog.FileName);
        }