private void RedrawPolygon(Figure f) { ClearPB(); Graphics g = Graphics.FromImage(pictureBox1.Image); Point[] points = new Point[f.Points().Count]; int i = 0; foreach (var p in f.Points()) { points[i] = new Point(ToPictureBoxX(p.x), ToPictureBoxY(p.y)); i += 1; } Pen pen = new Pen(Color.Red); g.DrawPolygon(pen, points); pictureBox1.Invalidate(); }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (CurrPanel == 0) { Graphics g = Graphics.FromImage(pictureBox1.Image); Pen pen = new Pen(Color.Red); if (Mode == 1) { //f.Add(new CustomPoint(e.X, e.Y)); f.Add(new CustomPoint(ToDekartX(e.X), ToDekartY(e.Y))); g.DrawRectangle(pen, e.X, e.Y, 1, 1); pictureBox1.Invalidate(); } else { if (f.Points().Count < 2) { //f.Add(new CustomPoint(e.X, e.Y)); f.Add(new CustomPoint(ToDekartX(e.X), ToDekartY(e.Y))); g.DrawRectangle(pen, e.X, e.Y, 1, 1); pictureBox1.Invalidate(); } } } if (CurrPanel == 1) { if (comboBox2.SelectedIndex == 1) { if (FindControl(panel1, "cb1") != null) { if (!(FindControl(panel1, "cb1") as CheckBox).Checked) { Label l11 = FindControl(panel1, "l11") as Label; Label l12 = FindControl(panel1, "l12") as Label; Button b1 = FindControl(panel1, "b1") as Button; b1.Enabled = true; if (e.Button == MouseButtons.Left) { l11.Text = "X: " + ToDekartX(e.X).ToString(); l12.Text = "Y: " + ToDekartY(e.Y).ToString(); } } } else { Label l11 = FindControl(panel1, "l11") as Label; Label l12 = FindControl(panel1, "l12") as Label; Button b1 = FindControl(panel1, "b1") as Button; b1.Enabled = true; /*if (e.Button == MouseButtons.Left) * { * l11.Text = "X: " + (ToValidPoint(e.X, e.Y).X - 500).ToString(); * l12.Text = "Y: " + ToValidPoint(e.X, e.Y).Y.ToString(); * }*/ } } if (Mode == 0) { if (comboBox2.SelectedIndex == 3) { Button b3 = FindControl(panel1, "b3") as Button; Label l31 = FindControl(panel1, "l31") as Label; Label l32 = FindControl(panel1, "l32") as Label; Label l33 = FindControl(panel1, "l33") as Label; Label l34 = FindControl(panel1, "l34") as Label; if (e.Button == MouseButtons.Left) { l31.Text = "X1: " + ToDekartX(e.X).ToString(); l32.Text = "Y1: " + ToDekartY(e.Y).ToString(); } if (e.Button == MouseButtons.Right) { l33.Text = "X2: " + ToDekartX(e.X).ToString(); l34.Text = "Y2: " + ToDekartY(e.Y).ToString(); b3.Enabled = true; } } } } if (CurrPanel == 2) { if (Mode == 1) { if (comboBox3.SelectedIndex == 0) { Label l21 = FindControl(panel2, "l21") as Label; Label l22 = FindControl(panel2, "l22") as Label; Button b5 = FindControl(panel2, "b5") as Button; if (e.Button == MouseButtons.Left) { l21.Text = "X: " + ToDekartX(e.X).ToString(); l22.Text = "Y: " + ToDekartY(e.Y).ToString(); } b5.Enabled = true; } } else { if (comboBox3.SelectedIndex == 0) { Label l11 = FindControl(panel2, "l11") as Label; Label l12 = FindControl(panel2, "l12") as Label; Button b4 = FindControl(panel2, "b4") as Button; { l11.Text = "X: " + ToDekartX(e.X).ToString(); l12.Text = "Y: " + ToDekartY(e.Y).ToString(); } b4.Enabled = true; } } } }