private void draw_Click(object sender, EventArgs e) { if (IsInt(tb_x1.Text, tb_y1.Text, tb_x2.Text, tb_y2.Text) && (cb_figures.SelectedIndex > -1) && ((Convert.ToInt32(tb_x1.Text, 10) < picture.Width) && (Convert.ToInt32(tb_y1.Text, 10) < picture.Height) && (Convert.ToInt32(tb_x2.Text, 10) < picture.Width) && (Convert.ToInt32(tb_y2.Text, 10) < picture.Height))) { Point topLeft = new Point(Convert.ToInt32(tb_x1.Text, 10), Convert.ToInt32(tb_y1.Text)); Point bottomRight = new Point(Convert.ToInt32(tb_x2.Text, 10), Convert.ToInt32(tb_y2.Text)); figure = maker.FactoryMethod(fatness, color, topLeft, bottomRight); figureList.Add(figure); //figuresExs.Add(figure); figure.Draw(graphics); jsonList.Add(new InfoForJSON() { fatness = fatness, color = color, topLeft = topLeft, bottomRight = bottomRight, figureName = maker.ToString() }); currentFabrics.Add(maker); picture.Image = bmap; } else { //tb_x1.Text = tb_x2.Text = tb_y1.Text = tb_y2.Text = ""; MessageBox.Show(message, title_mess, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void openToolStripMenuItem_Click_1(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "/files"; openFileDialog.RestoreDirectory = true; openFileDialog.FileName = "figures"; openFileDialog.DefaultExt = ".json"; if (openFileDialog.ShowDialog() == DialogResult.OK) { StreamReader stream = new StreamReader(openFileDialog.OpenFile()); string data = stream.ReadToEnd(); { string[] dataArray = data.Split('\n'); foreach (string dataBlock in dataArray) { try { InfoForJSON jSON = JsonConvert.DeserializeObject <InfoForJSON>(dataBlock); foreach (Fabric fab in allFabrics) { if (jSON.figureName == fab.ToString()) { jsonList.Add(jSON); Fabric factory = fab; figure = factory.FactoryMethod(jSON.fatness, jSON.color, jSON.topLeft, jSON.bottomRight); figure.Draw(graphics); picture.Image = bmap; break; } } } catch (Exception ex) { MessageBox.Show(message, title_mess, MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } } } stream.Close(); } }
public void Crochet(MainFigure figure, Graphics g) { figure.Draw(g); }