Beispiel #1
0
        private void ClickOpen(object objSrc, EventArgs args)
        {
            if (!_isSaved)
            {
                if (MiscFunctions.SavingPictureMessageBox() == DialogResult.Yes)
                {
                    ClickSave(objSrc, args);
                }
            }
            var ofd = new OpenFileDialog
            {
                Filter       = @"Xml files (*.xml)|*.xml|All files (*.*)|*.*",
                DefaultExt   = "xml",
                AddExtension = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                drawPan.Refresh();
                drawPan.Invalidate();
                _lines.Clear();
                try
                {
                    _lines = Serializing.Deserialize(ofd.FileName);
                    MiscFunctions.DrawLinesList(_lines, drawPan.CreateGraphics());
                    shapesToolStripMenuItem.DropDownItems.Clear();
                    foreach (var line in _lines)
                    {
                        var lineItem = new ToolStripMenuItem
                        {
                            Size = new Size(129, 26),
                            Text = line.Name,
                        };
                        lineItem.Click += ShapesMenuItemClick;
                        shapesToolStripMenuItem.DropDownItems.Add(lineItem);
                        //listBox.Items.Add($"Added new line ({line.Name}), color: {Color.FromArgb(line.R, line.G, line.B).Name}");
                    }
                    SwitchMovingObject(_lines.Count > 0 ? _lines.Count : 0);
                }
                catch (InvalidOperationException exc)
                {
                    MessageBox.Show(
                        $@"File '{ofd.FileName}' is invalid\n\nException: {exc.Message}",
                        @"Invalid file was loaded",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                }
            }
            _isSaved = true;
        }