SHARE
TWEET

Untitled

a guest Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3.  
  4. namespace WindowsFormsApp1
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         Point posPrevious;
  9.  
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.  
  14.             Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
  15.  
  16.             using (Graphics g = Graphics.FromImage(bmp))
  17.             {
  18.                 g.Clear(Color.White);
  19.             }
  20.  
  21.             pictureBox1.BackgroundImage = bmp;
  22.         }
  23.  
  24.         private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  25.         {
  26.             if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
  27.             {
  28.                 using (var front = pictureBox1.CreateGraphics())
  29.                 {
  30.                     if (e.Button == MouseButtons.Left)
  31.                     {
  32.                         front.DrawLine(Pens.Black, posPrevious, e.Location);
  33.                     }
  34.                     else if (e.Button == MouseButtons.Right)
  35.                     {
  36.                         front.FillEllipse(Brushes.White, posPrevious.X - 5, posPrevious.Y - 5, 10, 10);
  37.                         front.FillEllipse(Brushes.White, e.Location.X - 5, e.Location.Y - 5, 10, 10);
  38.                         front.DrawLine(new Pen(Color.White, 10), posPrevious, e.Location);
  39.                     }
  40.                 }
  41.  
  42.                 posPrevious = e.Location;
  43.             }
  44.         }
  45.  
  46.         private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  47.         {
  48.             posPrevious = e.Location;
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top