Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Drawing;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- Point posPrevious;
- public Form1()
- {
- InitializeComponent();
- Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
- using (Graphics g = Graphics.FromImage(bmp))
- {
- g.Clear(Color.White);
- }
- pictureBox1.BackgroundImage = bmp;
- }
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
- {
- using (var front = pictureBox1.CreateGraphics())
- {
- if (e.Button == MouseButtons.Left)
- {
- front.DrawLine(Pens.Black, posPrevious, e.Location);
- }
- else if (e.Button == MouseButtons.Right)
- {
- front.FillEllipse(Brushes.White, posPrevious.X - 5, posPrevious.Y - 5, 10, 10);
- front.FillEllipse(Brushes.White, e.Location.X - 5, e.Location.Y - 5, 10, 10);
- front.DrawLine(new Pen(Color.White, 10), posPrevious, e.Location);
- }
- }
- posPrevious = e.Location;
- }
- }
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- posPrevious = e.Location;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement