none
How to embed MSPaint in vb.net RRS feed

  • Question

  • Good day everyone. Can you please help me with my program. Here is the idea, I am writing a program that the users can put their signatures on it and I am thinking that maybe I could use MSPaint then save it as an image file and save it on my database. The device I'm going to use is a touchpad. I don't know how to explain this clearly but the idea is simple. User Log IN > Verify User Account > Put their Signature on a picture box. By the way I am using Visual Basic .NET 2005. Thanks in advance guys. I will appreciate any comments and help from you. Good day.
    Sunday, August 21, 2011 10:11 AM

Answers

  • Thanks Carmelo. I appreciate your help. Do you think is it possible to have a paint work space only in my form? Because i would like to use only the work space for me to able to put signature on it. Thanks for your immediate response buddy.

    If i understand you clearly, you want the user to able to sign their signature in your application and save it as image file. If that is what you want, you can create your own freehand signature pad using picturebox instead of hosting another third party program within your application, and then save the image to file. Below is sample code, you can change the pen color and the size to suit your need

    Private mousePath As New System.Drawing.Drawing2D.GraphicsPath
      
    
     Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = MouseButtons.Left Then      
          mousePath.StartFigure()
        End If
      End Sub
    
     Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = MouseButtons.Left Then 
          Try
            mousePath.AddLine(e.X, e.Y, e.X, e.Y)  'Add mouse coordiantes to mousePath
            
          Catch
            
          End Try
    
        End If
    
        PictureBox1.Invalidate() 'Repaint the PictureBox 
      End Sub
    
     Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Try
          Dim CurrentPen = New Pen(Color.Black, 2) 'Set up the pen
          e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
          e.Graphics.DrawPath(CurrentPen, mousePath) 
          
        Catch ex As Exception
    
        End Try
    
      End Sub
    
    

    kaymaf

     


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Daryll Joe Monday, August 22, 2011 2:04 AM
    Sunday, August 21, 2011 4:10 PM
  • Kaymaf, good day to you buddy! Your answer to my thread last time really help me a lot. Now, I have another question. How can I save the image on my picture box and after saving, clear the field?

     The code below will save the signature and clear the screen

    'save method
     Sub saveSignature(ByVal savePath As String, ByVal pbx As PictureBox, ByVal imageSaveFormat As System.Drawing.Imaging.ImageFormat)
     Dim bit As New Bitmap(pbx.Width, pbx.Height)
     Dim g As Graphics = Graphics.FromImage(bit)
     Dim peArgs As New PaintEventArgs(g, New Rectangle(Point.Empty, bit.Size))
     Me.InvokePaint(pbx, peArgs)
     bit.Save(savePath, imageSaveFormat)
     g.Dispose()
     bit.Dispose()
     peArgs.Dispose()
     End Sub
     
    'clear signature pad
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       PictureBox1.CreateGraphics.Clear(PictureBox1.BackColor)
       mousePath.Reset()     
      End Sub
    'Save signature
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      saveSignature("C:\testImage.png", PictureBox1, System.Drawing.Imaging.ImageFormat.Png)
      End Sub
    

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Daryll Joe Thursday, August 25, 2011 6:24 AM
    Wednesday, August 24, 2011 11:46 AM

All replies

  • Hello Daryll Joe,

    Good day everyone. Can you please help me with my program. Here is the idea, I am writing a program that the users can put their signatures on it and I am thinking that maybe I could use MSPaint then save it as an image file and save it on my database. The device I'm going to use is a touchpad. I don't know how to explain this clearly but the idea is simple.User Log IN > Verify User Account > Put their Signature on a picture box. By the way I am using Visual Basic .NET 2005. Thanks in advance guys. I will appreciate any comments and help from you. Good day.


    try to see this thread http://social.msdn.microsoft.com/Forums/en-US/vbinterop/thread/64272f0f-e9e3-485d-b191-5f7651196870/

     

    Regards.


    Carmelo La Monica http://community.visual-basic.it/carmelolamonica/

    WordPress  http://carmelolamonica.wordpress.com/

    Sunday, August 21, 2011 10:50 AM
  • Thanks Carmelo. I appreciate your help. Do you think is it possible to have a paint work space only in my form? Because i would like to use only the work space for me to able to put signature on it. Thanks for your immediate response buddy.
    Sunday, August 21, 2011 12:26 PM
  • Thanks Carmelo. I appreciate your help. Do you think is it possible to have a paint work space only in my form? Because i would like to use only the work space for me to able to put signature on it. Thanks for your immediate response buddy.

    If i understand you clearly, you want the user to able to sign their signature in your application and save it as image file. If that is what you want, you can create your own freehand signature pad using picturebox instead of hosting another third party program within your application, and then save the image to file. Below is sample code, you can change the pen color and the size to suit your need

    Private mousePath As New System.Drawing.Drawing2D.GraphicsPath
      
    
     Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = MouseButtons.Left Then      
          mousePath.StartFigure()
        End If
      End Sub
    
     Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = MouseButtons.Left Then 
          Try
            mousePath.AddLine(e.X, e.Y, e.X, e.Y)  'Add mouse coordiantes to mousePath
            
          Catch
            
          End Try
    
        End If
    
        PictureBox1.Invalidate() 'Repaint the PictureBox 
      End Sub
    
     Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Try
          Dim CurrentPen = New Pen(Color.Black, 2) 'Set up the pen
          e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
          e.Graphics.DrawPath(CurrentPen, mousePath) 
          
        Catch ex As Exception
    
        End Try
    
      End Sub
    
    

    kaymaf

     


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Daryll Joe Monday, August 22, 2011 2:04 AM
    Sunday, August 21, 2011 4:10 PM
  • Hi Kaymaf, thanks for your help. You've got what I want to do and I tried your sample code a while ago and it works! Thanks a lot.
    Monday, August 22, 2011 2:04 AM
  • Kaymaf, good day to you buddy! Your answer to my thread last time really help me a lot. Now, I have another question. How can I save the image on my picture box and after saving, clear the field?
    Wednesday, August 24, 2011 3:52 AM
  • Hi Daryll Joe,

    When a customer signs in though, no two signatures will be exactly identical in terms of the amount

    of time the mouse is down and so on. For example my initial letter "J" will not always look the same

     in terms of software for a simple computer program.

     

    I think that a program that recognises the patterns of a persons signature would be quite a complex piece of code.

     



    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.
    Wednesday, August 24, 2011 4:08 AM
  • Kaymaf, good day to you buddy! Your answer to my thread last time really help me a lot. Now, I have another question. How can I save the image on my picture box and after saving, clear the field?

    Hi again Daryll,

    For each new question please click on ASK  A QUESTION near the top of the list of threads in these forums

    rather than making a very long thread with one question after another, thank you.

     



    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Wednesday, August 24, 2011 4:10 AM
  • Hi again Daryll,

    Here is a way to actually EMBED MSPaint inside a VB.Net Form:>>

     

    Public Class Form1
    
      Public Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Me.Size = New Size(My.Computer.Screen.WorkingArea.Width * 3 \ 4, My.Computer.Screen.WorkingArea.Height * 3 \ 4)
        Dim MyPSI As New ProcessStartInfo("mspaint.exe")
        Dim MyProcess As Process = Process.Start(MyPSI)
        System.Threading.Thread.Sleep(5000)
        SetParent(MyProcess.MainWindowHandle, Me.Handle)
    
      End Sub
    End Class
    


    Code for SetParent from this thread:>>

    http://social.msdn.microsoft.com/forums/en-us/vblanguage/thread/E9841AAB-03CC-446D-904D-2E23D1E93A99

     

    You could try a smaller value for

    System.Threading.Thread.Sleep(5000)
    
    
    like 4000 for 4 seconds as the value is in milliseconds.
    It would not work with 3000 on one of my laptop computers as it has lots of stuff on the hard-drive.



    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.
    Wednesday, August 24, 2011 4:30 AM
  • When a customer signs in though, no two signatures will be exactly identical in terms of the amount

    of time the mouse is down and so on. For example my initial letter "J" will not always look the same

     in terms of software for a simple computer program.

     

    I think that a program that recognises the patterns of a persons signature would be quite a complex piece of code.


    Signature capturing is mostly done in tablets or pocket PC.

    Some examples

    http://msdn.microsoft.com/en-us/library/aa446559.aspx

    http://forums.devbuzz.com/Signature_Capture_Tutorial/m_41070/tm.htm

    You might be able to get some code out of these samples.

    Identifying signature in windows application ?

    The easy solution to identify a signature is to divide both images (The signature entered by user and the one in database ) it in to small blocks, then compare these blocks with each other if you have 55% - 60% or above similar blocks then the signatures are OK.

    Identifying signatures can become a headache, If you take an example of a bank, most of its customers uses ATM cards instead of there signature on a check, when they are required to enter there signature after a long time, most of them have forgotten how there signature looked like. I suggest that you switch to Finger print scanner which is more reliable in this case and there is a lot of good material available on it.


    Please mark those posts as answer which answers your question. Faraz
    Wednesday, August 24, 2011 4:30 AM
  • Good day John and Faraz.. I appreciate your comments and suggestions. Actually, kaymaf satisfied my needs for my program. The only purpose of this is to save only the signature on my database and retrieve it whenever i need the signature, just for example when generating reports. But then, I'll try those links and suggestions for further knowledge and maybe it could help and it can make my program more effective. By the way, I am using touchscreen for this project. Thanks a lot guys! Have a nice day!
    Wednesday, August 24, 2011 5:57 AM
  • Kaymaf, good day to you buddy! Your answer to my thread last time really help me a lot. Now, I have another question. How can I save the image on my picture box and after saving, clear the field?

     The code below will save the signature and clear the screen

    'save method
     Sub saveSignature(ByVal savePath As String, ByVal pbx As PictureBox, ByVal imageSaveFormat As System.Drawing.Imaging.ImageFormat)
     Dim bit As New Bitmap(pbx.Width, pbx.Height)
     Dim g As Graphics = Graphics.FromImage(bit)
     Dim peArgs As New PaintEventArgs(g, New Rectangle(Point.Empty, bit.Size))
     Me.InvokePaint(pbx, peArgs)
     bit.Save(savePath, imageSaveFormat)
     g.Dispose()
     bit.Dispose()
     peArgs.Dispose()
     End Sub
     
    'clear signature pad
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       PictureBox1.CreateGraphics.Clear(PictureBox1.BackColor)
       mousePath.Reset()     
      End Sub
    'Save signature
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      saveSignature("C:\testImage.png", PictureBox1, System.Drawing.Imaging.ImageFormat.Png)
      End Sub
    

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Daryll Joe Thursday, August 25, 2011 6:24 AM
    Wednesday, August 24, 2011 11:46 AM
  • Thanks Again! You help me a lot with my project.
    Thursday, August 25, 2011 6:25 AM