Pen pen1 = new Pen(Color.White, 2);
Pen pen2 = new Pen(Color.Black, 2);
private Point p1, p2;
Graphics gdraw;
public Form1()
{
InitializeComponent();
Bitmap bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
this.pictureBox1.Image = bmp;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
gdraw = Graphics.FromImage(this.pictureBox1.Image) ; //this.pictureBox1.CreateGraphics();
gdraw.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
p2 = e.Location;
gdraw.DrawLine(pen2, p1, p2);
p1 = p2;
this.pictureBox1.Refresh();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
p1 = p2;
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
p1 = e.Location;
p2 = e.Location;
}
}
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image.Save("C://001.bmp");
Application.DoEvents();
this.pictureBox2.ImageLocation = "C://001.bmp";
}