teensee

Untitled

Apr 18th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace GrapgicalEditor
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         Color CurrentColor = Color.Black;
  16.         bool isPressed = false;
  17.         Point CurrentPoint;
  18.         Point PrevPoint;
  19.         Graphics g;
  20.         int x, y, lx, ly = 0;
  21.         Item curItem;
  22.  
  23.         public Form1()
  24.         {
  25.             InitializeComponent();
  26.  
  27.             //g = panel1.CreateGraphics();
  28.             textBox1.BackColor = Color.Black;
  29.         }
  30.  
  31.         public enum Item {
  32.             Rectangle, Ellipse, Pencil, Brush, Line
  33.         }
  34.  
  35.         private void Form1_Load(object sender, EventArgs e)
  36.         {
  37.             textBox1.ReadOnly = true;
  38.         }
  39.  
  40.         private void paint() {
  41.             //Pen p = new Pen(CurrentColor, (float)numericUpDown1.Value);
  42.             //g.DrawLine(p, PrevPoint, CurrentPoint);
  43.         }
  44.  
  45.         private void button1_Click(object sender, EventArgs e)
  46.         {
  47.             if (colorDialog1.ShowDialog() == DialogResult.OK){
  48.                 CurrentColor = colorDialog1.Color;
  49.                 textBox1.BackColor = colorDialog1.Color;
  50.             }
  51.         }
  52.  
  53.         private void button2_Click(object sender, EventArgs e)
  54.         {
  55.             panel1.Refresh();
  56.         }
  57.  
  58.         private void button3_Click(object sender, EventArgs e)
  59.         {
  60.             curItem = Item.Line;
  61.         }
  62.  
  63.         private void button4_Click(object sender, EventArgs e)
  64.         {
  65.             curItem = Item.Rectangle;
  66.         }
  67.  
  68.         private void MouseDown(object sender, MouseEventArgs e) {
  69.             isPressed = true;
  70.             CurrentPoint = e.Location;
  71.             x = e.X;
  72.             y = e.Y;
  73.         }
  74.  
  75.         private void MouseMove(object sender, MouseEventArgs e) {
  76.  
  77.             if (isPressed) {
  78.                 Graphics graph = panel1.CreateGraphics();
  79.                 switch (curItem)
  80.                 {
  81.                     case Item.Rectangle:
  82.                         graph.FillRectangle(new SolidBrush(CurrentColor), x, y, e.X - x, e.Y - y);
  83.                         break;
  84.                 }
  85.                 graph.Dispose();
  86.             }
  87.         }
  88.  
  89.         private void MouseUp(object sender, MouseEventArgs e) {
  90.             isPressed = false;
  91.             lx = e.X;
  92.             ly = e.Y;
  93.             if (curItem == Item.Line) {
  94.                 Graphics graph = panel1.CreateGraphics();
  95.                 graph.DrawLine(new Pen(new SolidBrush(CurrentColor), (float)numericUpDown1.Value), new Point(x, y), new Point(lx, ly));
  96.                 graph.Dispose();
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment