Draw Signature On Mobile Computer Screen (Portable Terminal Device) C#

Draw Signature On Mobile Computer Screen (Portable Terminal Device) C#
 
 
Fig 1 : Design Screen of Smart Device Application
 
Write the following code in the application
 
Name Spaces
  1. using System;  
  2. using System.Linq;  
  3. using System.Collections.Generic;  
  4. using System.ComponentModel;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.IO;  
  10. using System.Reflection;  
  11. using System.Drawing.Imaging;  
  12. using System.Collections;  
  13. using System.Runtime.InteropServices;  
In Partial Class
  1. public partial class Form2 : Form  
  2.     {  
  3.         string Img;  
  4.   
  5.   
  6.         private string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);  
  7.         private Signature cSignature;  
  8.         private Point? _Previous = null;  
  9.         private Pen _Pen = new Pen(Color.Black);  
Create Events of PictureBox
  1. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)  
  2.         {  
  3.             _Previous = new Point(e.X, e.Y);  
  4.             pictureBox1_MouseMove(sender, e);  
  5.         }  
  6.   
  7.         private void pictureBox1_MouseMove(object sender, MouseEventArgs e)  
  8.         {  
  9.             if (_Previous != null)  
  10.             {  
  11.                 if (pictureBox1.Image == null)  
  12.                 {  
  13.                     Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);  
  14.                     using (Graphics g = Graphics.FromImage(bmp))  
  15.                     {  
  16.                         g.Clear(Color.White);  
  17.                     }  
  18.                     pictureBox1.Image = bmp;  
  19.                 }  
  20.                 using (Graphics g = Graphics.FromImage(pictureBox1.Image))  
  21.                 {  
  22.                     g.DrawLine(_Pen, _Previous.Value.X, _Previous.Value.Y, e.X, e.Y);  
  23.                 }  
  24.                 pictureBox1.Invalidate();  
  25.                 _Previous = new Point(e.X, e.Y);  
  26.             }  
  27.         }  
  28.   
  29.         private void pictureBox1_MouseUp(object sender, MouseEventArgs e)  
  30.         {  
  31.             _Previous = null;  
  32.         }  
Clear Button Click Event :
  1. private void btnClear_Click_1(object sender, EventArgs e)  
  2.         {  
  3.             pictureBox1.Image = null;  
  4.         }  
Lets see the output below : 
 
 
 Its Done
 
Ebook Download
View all
Learn
View all