Click here to Skip to main content
Click here to Skip to main content

Scratchpad/Signature Capture as BMP on Pocket PC

By , 6 Sep 2006
 

Sample Image - SignaturePPC02.gif Sample Image - SignaturePPC02.gif

Sample Image - SignaturePPC02.gif

Introduction

This control class allows a user to take a colored jot down note or signature, and save it as BMP file in the Pocket PC. This easy to use code can be plugged into any .NET application to take scribbles.

Background

Quite for a long time, I was looking for a free Signature control or some thing like that, that I could use in my own application without overloading it with bulkier codes. I was looking for some thing where I could change the pen color, width, and so on. In the internet knowledge bases, there was very few information on this, and most did not suit my needs. Later, I thought of assembling the available code and stripping down the un-needed portions, and fine-tuning the code to the level of my expectations.

Thought, may be a few people like me are still looking for this kind of a snippet and thought of sharing it. There are a few portions in this code that a programmer can even modify, like make the pen width changeable, save image as JPG or GIF etc.

Using the code

Copy the Signature.cs file to any of your Pocket PC 2003 projects. Add a Panel control to the visual form. Put this code as described and get the project rolling with signature capture capability.

Here, I have added a Panel:

private System.Windows.Forms.Panel pnlSignature;
private Signature cSignature;

Later in the constructor, or in the form Load event, you can add:

cSignature = new Signature();
cSignature.Location = pnlSignature.Location;
cSignature.Size = pnlSignature.Size;
this.pnlSignature.Visible = false;
this.Controls.Add(cSignature);

Under any Button's Click event, you can write this code to save the file under your desired location with a name:

cSignature.Save(Path.Combine(AppPath, "CapturedPicture.bmp"));

Similarly, you can change the pen color by calling:

cSignature.SetPenColor(Color.Blue);

or load a previously saved picture of the same size, using:

cSignature.LoadImage(Path.Combine(AppPath, 
        "PreviouslyCapturedPicture.bmp"));

Tips and Tricks:

  1. Do not forget to set the Visibility of the Panel to false, as we need to see the control, not the Panel. Here, the Panel is just a container.
  2. It is more important to set the size of the signature control to the size of the loaded picture and the Panel size, else it may not work.

Points of Interest

While working on this, I changed the pen width by changing the following lines of code. Obviously, there must be a better way to do this than what I did.

GraphicsHandle.DrawLine(SignaturePen, l.StartX+1, 
                      l.StartY, l.EndX+1,l.EndY);
GraphicsHandle.DrawLine(SignaturePen, l.StartX, 
                  l.StartY+1, l.EndX,l.EndY+1);
GraphicsHandle.DrawLine(SignaturePen, l.StartX+1, 
                  l.StartY+1, l.EndX+1,l.EndY+1);
GraphicsHandle.DrawLine(SignaturePen, l.StartX, 
                      l.StartY, l.EndX,l.EndY);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

RajeshNayak
Web Developer
United States United States
Rajesh Nayak currently working with CSDC Systems Inc.'s (canada East Zone - R&D Branch) as Product Manager-Mobile Solutions.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralWinforms User Signature Capture Controlmemberjay_dubal31-Mar-11 0:19 
check out WINSIGN winformsignaturecapture.com
GeneralSignature Capture in standalone(Windows Forms Application)memberradhikakiran1313-Jan-10 9:37 
Hi Rajesh,
Signature Capture code was very helpful in the Smart device application I have created. Now, I am trying to use this Signature class in Windows Forms Application to be used on netbooks with OS Windows XP Pro. The windows application has an error 'Unable to load Coredll.dll'. Is there a way to avoid the error and get the signature capture functionality working on Windows Forms Application??
 
Please reply with any suggestion you have.
 
Thanks in advance.
RadhikaKiran
GeneralSaves a white background (no ink marks)memberJacob Dixon16-Nov-09 10:46 
I have a problem with this that I cannot figure out on my own.
 
HEre is what I am doing:
 
Framework 3.5
Visual Studio 2008
 
Deploying to a Pocket PC (Windows Mobile 2003).
 
Ok I had it working just fine but I added some code to the form (not related to the signature) and it stopped. I remove my code and it still didn't work!
 
        private string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        private Signature cSignature = null;
 
        public Sig()
        {
            InitializeComponent();
 
            cSignature = new Signature();
            cSignature.Location = pnlSig.Location;
            cSignature.Size = pnlSig.Size;
            this.Controls.Add(cSignature);
        }
 
        private void Sig_Load(object sender, EventArgs e)
        {
            cSignature.SetPenColor(Color.Black);
 
            if (File.Exists(Path.Combine(AppPath, "CapturedSignature1.bmp")))
            {
                DialogResult result = MessageBox.Show("There is a signature that exist.\nWould you like to open it?", "Open?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    cSignature.LoadImage(Path.Combine(AppPath, "CapturedSignature1.bmp"));
                }
            }
        }
 
        private void menuItem1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
 
            //Save to a File
            cSignature.Save(Path.Combine(AppPath, "CapturedSignature1.bmp"));
 
            Cursor.Current = Cursors.Default;
        }
 
        private void menuItem2_Click(object sender, EventArgs e)
        {
        }
 
When you click save it creates a file but it is blank. You can write on it and everything just fine. It just isn't saving what you write to the file
Question2 color bitmapmemberNatarajan R22-Jul-09 22:54 
Thank you for the source code, it was very helpful.
However i need to capture the signature and save it as 2 color bitmap file (only 2 color bitmap file can be printed using thermal printer)
 
Can you please help with this.
 
Thanks and regards,
Natarajan k r
Questionhow do I get this to workmemberLisa Mulcahy27-May-09 4:22 
Hi
 
I want to open your code and run it in visual studio 2008? However it wont let me as I need to convert from whatever you developed it in? vs 2005? Anyway it wont convert correctly either due to permissions on your files.
 
I just dbl clicked on the solution and it tried to open it in vs 2008 but failed. Is there anyway around this?
 
I also tried to add the signature class to an existing project Smart Device I created but it wont recognise Signature.cs as a class.
 
I am very new to this so any suggestions would be great.
 
Thanks in advance
 
Lisa
AnswerRe: how do I get this to workmembergrandk28-Nov-09 8:44 
I have the same problem to add the signature.cs clas into my project. I'm using VS2008 and the conversion went perfect and I can test it out on the pocket pc.
 
But if I want to add the signature.cs into my project, then it doesn't recognise the class. I'm using VB instead of CS code.
 
Does anyone has a solution for this ?
 
Thx in advance,
Kurt
NewsASP.NET Signature Capturememberjay_dubal26-Aug-08 0:33 
I have used http://mysignature.brinkster.net for online asp.net signature capture
Generalgetting error during save the filemembersouravmoy sau18-Jun-08 2:44 
hello
i am merge the signature.cs file and use the controls as it is in the example,
but i am getting and exception during save the file and the exception can't be displayed in details
 
I am using VS 2008 and building windows mobile 5.0 application
 
please help regarding this problem
 
Thanks in advance
sourav
QuestionRunning with parameter (e.g. Filename)memberconny12319-Nov-07 5:06 
Hi Rajesh,
 
good job for coding this.
 
I am not very good in coding c# - my focus lays on VB6 and VB.NET.
 
My question is: Is it possible to call your software "SignaturePPC.exe" with a parameter in it (e.g. "SignaturePPC.exe SignatureFileName.bmp") ?
 
So, I can call your application with the shell command and can parameter the filename for saving the bitmap.
 
Is this possible ?
 
Thanks a lot for your answer.
 
Greetings from Germany, Marc.
QuestionHow can I give a BackgroundImage for the Control.memberajsri7727-Sep-07 1:02 
I want to give a background Image to the control, like "Please Sign Here".
 
How can i do that in this code..
 
Please help me.
 
Regards
Sriram Prasad

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 6 Sep 2006
Article Copyright 2006 by RajeshNayak
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid