Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace _2056
- {
- public partial class myPaint : Form
- {
- /*Variables*/
- /*Start position of mouse on the canvas*/
- private int mouseStartX = 0;
- private int mouseStartY = 0;
- /*Current position of the mouse on the canvas*/
- private int mouseCurrentX = 0;
- private int mouseCurrentY = 0;
- /*Start position for rectangle on the canvas*/
- private int recStartPositionX = 0;
- private int recStartPositionY = 0;
- /*Size of the rectangle on the canvas*/
- private int recSizeY = 0;
- private int recSizeX = 0;
- /*Chek if mouse is down*/
- private bool mouseDown = false;
- /*Bitmap objects*/
- private Bitmap bm;
- /*Determine what shape is selected*/
- private int shapeSelected = 0;
- /*Color of the line of the shapes*/
- private Color linePaintColor;
- /*Color of the fill line of the shapes*/
- private Color lineFillPaintColor;
- public myPaint()
- {
- InitializeComponent();
- bm = new Bitmap(paint_Canvas.Width, paint_Canvas.Height);
- linePaintColor = Color.Black;
- lineFillPaintColor = Color.Black;
- }
- private void paint_Canvas_Paint(object sender, PaintEventArgs e)
- {
- Graphics gPaint = e.Graphics;
- if (mouseDown == true)
- {
- Pen size = new Pen(linePaintColor);
- if (shapeSelected == 1)
- {
- gPaint.DrawLine(size, new Point(mouseStartX, mouseStartY),
- new Point(mouseCurrentX + mouseStartX, mouseCurrentY + mouseStartY));
- }
- else if (shapeSelected == 2)
- {
- gPaint.DrawEllipse(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
- }
- else if (shapeSelected == 3)
- {
- gPaint.DrawRectangle(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
- }
- }
- gPaint.DrawImage(bm, new Point(0, 0));
- }
- private void ToolBar_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- private void paint_Canvas_MouseUp(object sender, MouseEventArgs e)
- {
- mouseDown = false;
- }
- private void paint_Canvas_MouseDown(object sender, MouseEventArgs e)
- {
- Pen size1 = new Pen(linePaintColor);
- Graphics gPaint = Graphics.FromImage(bm);
- if (mouseDown = true)
- {
- mouseStartX = e.X;
- mouseStartY = e.Y;
- mouseCurrentX = e.X - mouseStartX;
- mouseCurrentY = e.Y - mouseStartY;
- }
- if(e.Button == MouseButtons.Left)
- {
- Pen size = new Pen(linePaintColor);
- mouseDown = true;
- Graphics gPaint1 = Graphics.FromImage(bm);
- if(shapeSelected == 1)
- {
- gPaint.DrawLine(size, new Point(mouseStartX, mouseStartY),
- new Point(mouseCurrentX + mouseStartX, mouseCurrentY + mouseStartY));
- }
- else if (shapeSelected == 2)
- {
- gPaint.DrawEllipse(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
- }
- else if (shapeSelected == 3)
- {
- gPaint.DrawRectangle(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
- }
- }
- }
- private void paint_Canvas_MouseMove(object sender, MouseEventArgs e)
- {
- if (mouseDown == true)
- {
- mouseCurrentX = e.X - mouseStartX;
- mouseCurrentY = e.Y - mouseStartY;
- paint_Canvas.Invalidate();
- }
- else
- {
- paint_Canvas.Invalidate();
- }
- recStartPositionX = Math.Min(mouseStartX, e.X);
- recStartPositionY = Math.Min(mouseStartY, e.Y);
- recSizeX = Math.Max(mouseStartX, e.X);
- recSizeY = Math.Max(mouseStartY, e.Y);
- }
- private void lineBtn_Click(object sender, EventArgs e)
- {
- shapeSelected = 1;
- }
- private void circleBtn_Click(object sender, EventArgs e)
- {
- shapeSelected = 2;
- }
- private void square_Btn_Click(object sender, EventArgs e)
- {
- shapeSelected = 3;
- }
- private void black_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Black;
- }
- private void red_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Red;
- }
- private void blue_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Blue;
- }
- private void green_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Green;
- }
- private void yellow_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Yellow;
- }
- private void purple_Btn_Click(object sender, EventArgs e)
- {
- linePaintColor = Color.Purple;
- }
- private void otherColors_Btn_Click(object sender, EventArgs e)
- {
- ColorDialog colorWheel = new ColorDialog();
- if (colorWheel.ShowDialog() == DialogResult.OK)
- {
- linePaintColor = colorWheel.Color;
- }
- }
- private void toolStripButton15_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Black;
- }
- private void toolStripButton16_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Red;
- }
- private void toolStripButton17_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Blue;
- }
- private void toolStripButton18_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Green;
- }
- private void toolStripButton19_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Yellow;
- }
- private void toolStripButton20_Click(object sender, EventArgs e)
- {
- lineFillPaintColor = Color.Purple;
- }
- private void toolStripButton21_Click(object sender, EventArgs e)
- {
- ColorDialog colorWheel1 = new ColorDialog();
- if (colorWheel1.ShowDialog() == DialogResult.OK)
- {
- lineFillPaintColor = colorWheel1.Color;
- }
- }
- private void clrBtn_Click(object sender, EventArgs e)
- {
- Graphics gPaint = CreateGraphics();
- gPaint.Clear(SystemColors.Control);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement