using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CSPaint
{
public partial class Form1 : Form
{
Bitmap bitmap;
Graphics graphics;
Point oldPoint;
bool isDrag = false;
public Form1()
{
InitializeComponent();
bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, PixelFormat.Format24bppRgb);
graphics = Graphics.FromImage(bitmap);
oldPoint = new Point(0,0);
pictureBox1.Image = bitmap;
graphics.Clear(Color.White);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isDrag = true;
oldPoint = e.Location;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isDrag = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isDrag)
{
graphics.DrawLine(new Pen(Color.Black, 4), oldPoint, e.Location);
oldPoint = e.Location;
pictureBox1.Image = bitmap;
}
}
}
}