using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { Pen mypen; bool bmousedown = false; Point prevpoint; Graphics g; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { mypen = new System.Drawing.Pen(System.Drawing.Color.Black); g = pictureBox1.CreateGraphics(); mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; mypen.Color = Color.Black; mypen.Width = 1.0f; } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { prevpoint = e.Location; bmousedown = true; } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { bmousedown = false; } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (bmousedown) { Point thispoint = e.Location; if (prevpoint.X == 0 && prevpoint.Y == 0) { prevpoint = thispoint; return; } g.DrawLine(mypen, thispoint.X, thispoint.Y, prevpoint.X, prevpoint.Y); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; prevpoint = thispoint; } } private void btnSave_Click(object sender, EventArgs e) { using (SaveFileDialog sfdlg = new SaveFileDialog()) { sfdlg.Title="Save Dialog"; sfdlg.Filter="Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*"; if(sfdlg.ShowDialog(this)==DialogResult.OK) { using (Bitmap bmp = new Bitmap(pictureBox1.Width,pictureBox1.Height)) { pictureBox1.DrawToBitmap(bmp,new Rectangle(0,0,bmp.Width ,bmp.Height)); pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); pictureBox1.Image.Save("c://cc.Jpg"); bmp.Save(sfdlg.FileName); MessageBox.Show("Saved Successfully....."); } } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)