public FormMain() { InitializeComponent(); ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); panelColorSelect.BackColor = Color.Black; panelBackgroundSelect.BackColor = Color.White; pictureBoxDraw.BackColor = Color.White; DoubleBuffered = true; Shapes = new ShapeList(Color.White, listBoxShapes); Layers = new Layer(pictureBoxDraw.Width, pictureBoxDraw.Height, Shapes); kBinder = new KnownTypesBinder(); ConfigSerializer = new ConfigSerializer(); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { if (ConfigSettings == null) { MessageBox.Show("Config wasn't load."); return; } openFileDialog.Filter = "Image files (*." + ConfigSettings.ImageSettings.ImageExtension + ")|*." + ConfigSettings.ImageSettings.ImageExtension; openFileDialog.InitialDirectory = ConfigSettings.ImageSettings.ImagePath; openFileDialog.RestoreDirectory = false; if (openFileDialog.ShowDialog() != DialogResult.Cancel) { try { string json = File.ReadAllText(openFileDialog.FileName); Shapes = JsonConvert.DeserializeObject<ShapeList>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, Binder = kBinder }); Shapes.SetListBox(listBoxShapes); Layers = new Layer(pictureBoxDraw.Width, pictureBoxDraw.Height, Shapes); Shapes.RefreshListBox(); panelBackgroundSelect.BackColor = Shapes.BackColor; Layers.UpdateStatic(); pictureBoxDraw.Image = Layers.DynamicLayer; } catch (JsonSerializationException) { MessageBox.Show("Can't find some shapes, contained in image. Please, load them."); } catch (Exception) { MessageBox.Show("Error while reading file."); } } ClearFileDialog(); }
public Layer(int width, int height, ShapeList sh) { Width = width; Height = height; Shapes = sh; }