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. private string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
  5. private Signature cSignature;
  6. private Point? _Previous = null;
  7. 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. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  7. {
  8. if (_Previous != null)
  9. {
  10. if (pictureBox1.Image == null)
  11. {
  12. Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  13. using (Graphics g = Graphics.FromImage(bmp))
  14. {
  15. g.Clear(Color.White);
  16. }
  17. pictureBox1.Image = bmp;
  18. }
  19. using (Graphics g = Graphics.FromImage(pictureBox1.Image))
  20. {
  21. g.DrawLine(_Pen, _Previous.Value.X, _Previous.Value.Y, e.X, e.Y);
  22. }
  23. pictureBox1.Invalidate();
  24. _Previous = new Point(e.X, e.Y);
  25. }
  26. }
  27. private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  28. {
  29. _Previous = null;
  30. }
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

Comments

Join the conversation! Your thoughts help the community grow.