This is a creation in Article, where the information may have evolved or changed.
Recent projects need to use the function of handwritten electronic signature, pick to choose the last Mengtian write2go this tablet device, because the tablet directly on the top of an electronic ink display, the writing is obtained, you can also see the written handwriting
After installing the Mengtian driver and its own application, the test found that it works by using the Windows Clipboard as an intermediate bridge to exchange image data, each time you sign the first need to start a mengtian called "Mengtian is written" program:
After all, the handwriting of the handwriting to the computer when walking or the tablet's resistance screen, so the handwriting effect is certainly not as good as the electronic ink screen shown above, press the Send button on the device, the handwriting will be saved as a picture in the form of the Windows Clipboard, using the previous article written to the Windows Clipboard Content monitoring method , you can call the handwriting picture in your own program, which involves several technical points:
- Call Mengtian's "write-through" program when clicking on the signature area in the program
- Monitor the Windows clipboard to show that the image data is updated into the clipboard when it is called into the PictureBox control in its own program
- Writes the signature ink image type data displayed in the PictureBox control to the database
- Reads the image type data from the database and displays it in the WinForm PictureBox control
The complete code is as follows:
Imports system.ioimports System.Data.SqlClientPublic Class Clipboardmon '------------------ Monitor Clipboard Data code start------------------#Region "Definitions" ' Constants for API Calls ... Private Const wm_drawclipboard As Integer = &h308 Private const wm_changecbchain As Integer = &h30d ' Handle For next Clipboard Viewer ... Private Mnextclipboardviewerhwnd as IntPtr ' API declarations ... Declare auto function setclipboardviewer Lib "user32" (ByVal HWnd as INTPTR) as IntPtr Declare Auto function Changeclip Boardchain Lib "user32" (ByVal HWnd as INTPTR, ByVal Hwndnext as IntPtr) as Boolean Declare Auto Function SendMessage L IB "User32" (ByVal HWnd as INTPTR, ByVal Msg as Integer, ByVal WParam as INTPTR, ByVal LParam as IntPtr) as Long#end Regio N#region "contructor" public Sub newviewer () ' InitializeComponent () ' To register this form as a Clipboa Rd Viewer ... Clipboard.clear () Mnextclipboardviewerhwnd = SetClipboardViewer (me.handle) EnD sub#end region#region "Message Process" ' Override WndProc to get messages ... Protected Overrides Sub WndProc (ByRef m as Message) Select case m.msg case is = Wm_drawclipboard ' the CL Ipboard has changed ... ' ########################################################################## ' Process Clipboard here:) .... .................... ' ########################################################################## SendMessage (mnextclipboardviewe Rhwnd, M.msg, M.wparam, m.LParam) ' Show picture information in the Clipboard If clipboard.containsimage () = True Then pictureBox1.Image = Clipboard.getimage () picturebox1.update () End If Case was = Wm_changecbchain ' Another clipboard viewer has removed itself ... If M.wparam = CType (Mnextclipboardviewerhwnd, IntPtr) then Mnextclipboardviewerhwnd = m.LParam ElsE SendMessage (Mnextclipboardviewerhwnd, m.msg, M.wparam, m.LParam) End If End Sel ECT Mybase.wndproc (m) End sub#end region Private Sub clipboardmon_load (ByVal sender as Object, ByVal e as Sys Tem. EventArgs) Handles me.load newviewer () End Sub '------------------monitor clipboard Data code end------------------' <su Mmary> "' Click on the signature area to automatically run Mengtian that is the write-through program ' </summary> ' <param name= ' sender ' ></param> ' <pa Ram Name= "E" ></param> "<remarks></remarks> Private Sub PictureBox1_Click (ByVal sender as Sys Tem. Object, ByVal e as System.EventArgs) Handles Picturebox1.click ' position Mengtian that is the location path of the write-through program Dim Writepath as String = Env Ironment. GetFolderPath (Environment.SpecialFolder.ProgramFilesX86) + "\penpower Write2go\bin\ppstartupapp.exe" Process.Start (Writepath) End Sub ' <summary> ' saves the image in the current PictureBox to the database ' </summary> ' <param name= ' sender '></param> ' <param name= ' e ' ></param> ' <remarks></remarks> Private Sub Butto N1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click Dim ms as New Memorystre AM () Dim Breturn () as Byte = Nothing Me.PictureBox1.Image.Save (MS, Imaging.ImageFormat.Jpeg) Breturn = Ms. GetBuffer Ms. The Close () Using conn as New SqlConnection (My.Settings.piaojuConnectionString) Conn. Open () Dim cmd as New sqlclient.sqlcommand () cmd. Connection = conn cmd. CommandText = "INSERT into Paper_baozhangshenpidan (paperid,applysign) VALUES (' 20160227 ', @img)" Dim par as New S Qlclient.sqlparameter ("@img", sqldbtype.image) par. Value = Breturn cmd. Parameters.Add (PAR) Dim t as Integer = Integer.parse (cmd). ExecuteNonQuery ()) If T > 0 then MsgBox ("Success") Else MsgBox ("Fai LE ") End If Conn. Close () End Using End Sub ' <summary> ' reads the image type data from the database and displays it in the PictureBox control ' ' </summary> ; "' <param name=" sender "></param>" <param name= "E" ></param> "<remarks></remar Ks> Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button2.click Dim imgdata (0) as Byte Using conn as New SqlConnection (My.Settings.piaojuConnectionString) Conn. Open () Dim cmd as New SqlCommand cmd. Connection = conn cmd. CommandText = "Select * from Paper_baozhangshenpidan where paperid= ' 20160227 '" Dim SDR as SqlDataReader = CMD.E Xecutereader SDR. Read () Imgdata = SDR ("Applysign") Dim mystream As New MemoryStream (imgdata) Dim img As Im Age = Image.fromstream (MyStream, True) Me.PictureBox1.Image = img Me.PictureBox1.Refresh() MyStream. Close () Conn. Close () End Using End subend Class
Note:
The data type of column ' Applysign ' in the database is image, which is used to hold the byte data of the picture.