private void ZoomPictureBox1_MouseUp(object sender, MouseEventArgs e) { if (RectOn && moving) { try { Graphics g = Graphics.FromImage(zoomPictureBox1.Image); Rectangle TempRect = FunctionClass.CreateRect(x_y, x_y2); g.DrawRectangle(pen, TempRect); toolStripStatusLabel8.Text = Convert.ToString(TempRect.Height); toolStripStatusLabel11.Text = Convert.ToString(TempRect.Width); g.Dispose(); zoomPictureBox1.Invalidate(); } catch { } } else if (EllipsOn && moving) { try { Graphics g = Graphics.FromImage(zoomPictureBox1.Image); Rectangle TempRect = FunctionClass.CreateRect(x_y, x_y2); g.DrawEllipse(pen, TempRect); toolStripStatusLabel8.Text = Convert.ToString(TempRect.Height); toolStripStatusLabel11.Text = Convert.ToString(TempRect.Width); g.Dispose(); zoomPictureBox1.Invalidate(); } catch { } } else if (LineOn && moving) { try { Graphics g = Graphics.FromImage(zoomPictureBox1.Image); FunctionClass.DrawLine(x_y, x_y2, g, pen); g.Dispose(); zoomPictureBox1.Invalidate(); } catch { } } //Очистка ненужной истории if (History[History.Count - 1] != zoomPictureBox1.image) { ChangeHistoty(); Undo_redo(); } moving = false; }
private void ZoomPictureBox1_Paint(object sender, PaintEventArgs e) { if (moving) { if (RectOn) { e.Graphics.DrawRectangle(new Pen(pen.Color, pen.Width * zoomPictureBox1.Zoom), FunctionClass.CreateRect(RealLocation1, RealLocation2)); } else if (EllipsOn) { e.Graphics.DrawEllipse(new Pen(pen.Color, pen.Width * zoomPictureBox1.Zoom), FunctionClass.CreateRect(RealLocation1, RealLocation2)); } else if (LineOn) { FunctionClass.DrawLine(RealLocation1, RealLocation2, e.Graphics, new Pen(pen.Color, pen.Width * zoomPictureBox1.Zoom)); } } else if (TextOn) { e.Graphics.DrawString(textBox1.Text, new Font(TextFont.FontFamily, TextFont.Size * zoomPictureBox1.Zoom, TextFont.Style), new SolidBrush(FontColor), TextPoint); } }
private void ZoomPictureBox1_MouseClick(object sender, MouseEventArgs e) { if (Control.ModifierKeys == Keys.Shift && PenOn) { if (IntShift != 2) { IntShift += 1; } else { Graphics g = Graphics.FromImage(zoomPictureBox1.Image); g.DrawLine(pen, PointShift, zoomPictureBox1.ClientToImagePoint(e.Location)); g.Dispose(); zoomPictureBox1.Invalidate(); } PointShift = zoomPictureBox1.ClientToImagePoint(e.Location); } else { IntShift = 1; } if (TextOn) { TextPoint = e.Location; textBox1.Visible = true; OkButton.Visible = true; CanleButton1.Visible = true; FontButton.Visible = true; zoomPictureBox1.AllowUserDrag = false; zoomPictureBox1.AllowUserZoom = false; ToolStripMenuItemZoom.Enabled = false; textBox1.Focus(); } else if (PipOn && (e.Button == MouseButtons.Left)) { Color color = Color.White; try { color = zoomPictureBox1.image.GetPixel(zoomPictureBox1.ClientToImagePoint(e.Location).X, zoomPictureBox1.ClientToImagePoint(e.Location).Y); } catch { } if (color.A == 0) { color = Color.White; button1.BackColor = color; numericUpDown2.Value = color.A; pen.Color = color; } else { button1.BackColor = color; numericUpDown2.Value = color.A; pen.Color = color; } } else if (FillOn && e.Button == MouseButtons.Left) { int x = zoomPictureBox1.ClientToImagePoint(e.Location).X; int y = zoomPictureBox1.ClientToImagePoint(e.Location).Y; if (x >= 0 && x < zoomPictureBox1.image.Width && y >= 0 && y < zoomPictureBox1.image.Height) { if (FunctionClass.GetPx(x, y, ref zoomPictureBox1).ToArgb() != pen.Color.ToArgb()) { FunctionClass.Fill(zoomPictureBox1.ClientToImagePoint(e.Location), pen.Color, ref zoomPictureBox1); } } } }