Konark

Untitled

Dec 3rd, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 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 WindowsFormsApplication3
  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.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.             g = panel1.CreateGraphics();
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             //Graphics gr = CreateGraphics();
  29.             //Pen p = new Pen(Color.Green);
  30.             DialogResult dlg = colorDialog1.ShowDialog();
  31.             if (dlg == System.Windows.Forms.DialogResult.OK)
  32.             {
  33.                 CurrentColor = colorDialog1.Color;
  34.             }
  35.         }
  36.  
  37.         private void panel1_MouseUp(object sender, MouseEventArgs e)
  38.         {
  39.             isPressed = false;
  40.         }
  41.  
  42.         private void panel1_MouseMove(object sender, MouseEventArgs e)
  43.         {
  44.             if (isPressed)
  45.             {
  46.                 PrevPoint = CurrentPoint;
  47.                 CurrentPoint = e.Location;
  48.                 ForPaint();
  49.             }
  50.         }
  51.  
  52.         private void panel1_MouseDown(object sender, MouseEventArgs e)
  53.         {
  54.             isPressed = true;
  55.             CurrentPoint = e.Location;
  56.         }
  57.  
  58.         private void ForPaint()
  59.         {
  60.             Pen p = new Pen(CurrentColor);
  61.             g.DrawLine(p, PrevPoint, CurrentPoint);
  62.         }
  63.  
  64.         private void button2_Click(object sender, EventArgs e)
  65.         {
  66.             panel1.Refresh();
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment