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 GrapgicalEditor
- {
- public partial class Form1 : Form
- {
- Color CurrentColor = Color.Black;
- bool isPressed = false;
- Point CurrentPoint;
- Point PrevPoint;
- Graphics g;
- int x, y, lx, ly = 0;
- Item curItem;
- public Form1()
- {
- InitializeComponent();
- //g = panel1.CreateGraphics();
- textBox1.BackColor = Color.Black;
- }
- public enum Item {
- Rectangle, Ellipse, Pencil, Brush, Line
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox1.ReadOnly = true;
- }
- private void paint() {
- //Pen p = new Pen(CurrentColor, (float)numericUpDown1.Value);
- //g.DrawLine(p, PrevPoint, CurrentPoint);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (colorDialog1.ShowDialog() == DialogResult.OK){
- CurrentColor = colorDialog1.Color;
- textBox1.BackColor = colorDialog1.Color;
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- panel1.Refresh();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- curItem = Item.Line;
- }
- private void button4_Click(object sender, EventArgs e)
- {
- curItem = Item.Rectangle;
- }
- private void MouseDown(object sender, MouseEventArgs e) {
- isPressed = true;
- CurrentPoint = e.Location;
- x = e.X;
- y = e.Y;
- }
- private void MouseMove(object sender, MouseEventArgs e) {
- if (isPressed) {
- Graphics graph = panel1.CreateGraphics();
- switch (curItem)
- {
- case Item.Rectangle:
- graph.FillRectangle(new SolidBrush(CurrentColor), x, y, e.X - x, e.Y - y);
- break;
- }
- graph.Dispose();
- }
- }
- private void MouseUp(object sender, MouseEventArgs e) {
- isPressed = false;
- lx = e.X;
- ly = e.Y;
- if (curItem == Item.Line) {
- Graphics graph = panel1.CreateGraphics();
- graph.DrawLine(new Pen(new SolidBrush(CurrentColor), (float)numericUpDown1.Value), new Point(x, y), new Point(lx, ly));
- graph.Dispose();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment