"WPF" Learning Notes (ii)--still an electronic signature board

Source: Internet
Author: User

This blog, the main talk about the implementation of electronic signature features stepped on several pits: 1. System.badimageformatexception abnormal; 2 Unable to load DLL "###.dll": The specified module could not be found. (Exception from hresult:0x8007007e); 3.WPF gets the handle of the control.

If you want to learn how to use InkCanvas in WPF to implement a feature similar to a signature pad (Doodle Board series), refer to my previous blog post.

Again, humorous, a large part of this blog is due to the InkCanvas version of the signature board was rejected. The reason for this is that the signature pad will be used for the user signature on the touchscreen, and the InkCanvas version of the handwritten signature on the touchscreen can be described with a bad experience. So, the final adoption of another solution: Call a C + + DLL (this DLL is provided by the company, and there is a WinForm version of the demo, I just need the right "to move Bricks" just fine), through the electronic signature pen to complete the signature.

The gossip is over, now let's talk about some of the questions:

1.system.badimageformatexception exception

This anomaly was triggered when I tried to compile the WinForm version of the demo, searching the web for a reason in a blog post: The target platform for the target program is inconsistent with the target compiler platform for a dependency. So I changed the target platform of the related project to x86, and the problem was solved. An example that modifies the target platform is provided below:

Approximate modification process: Right-click on the project/properties + compile = Target platform

2. Unable to load DLL "###.dll": The specified module could not be found

Vaguely remember a long time ago encountered this problem, but forget how to deal with the specific. So the internet search for a bit, on this issue a lot of posts, but all the same ... In general, the DLLs are copied manually to the bin directory in the project folder, and the DLLs are copied to the System32 directory; there is a solution that feels so big that the individual is not interested in seeing it. Come on! In my memory, this should not be a very troublesome thing ah, and now the VS so strong, still need to do this kind of thing manually?? Finally decided to explore, and finally found a solution.

I'm sure everyone here can see the problem. Copy to output directory of--dll (copy to export directory) The default option is never copy!! Get dirty, scare me quickly modify the copy if newer (if the update will re-copy a copy to the output directory, if you want to choose to always copy copy forever I do not block), and then this problem is not then. Of course, it is possible that the problem I encountered is relatively simple, this solution may not apply to certain situations, you can leave a message under the blog, we discuss together.

3. WPF Get control handle

Since the signature pad function of a DLL called C + + needs to be passed as a parameter to the signature pad, I'll take this place out here and talk about it.

Online about WPF gets the handle of the control a lot of posts, but with all due respect, mostly in the nonsense ~

For example, below:

Let me test a ticket in this way first:

We found that the two methods got the same handle as a hair ...

Listen to the old driver that WPF controls are drawn and do not assign a handle to each control, so the handle to the so-called control that is taken by this method is, in fact, the handle of the entire form. And our demand is to get the handle of the corresponding control, so we can only find a way to use WinForm.

Next, let's take a look at the specific steps:

1) Add two references (System.Windows.Forms and Windowsformsintegration)

To find these two libraries relatively quickly, I searched for the keyword "windows"

2) XAML

A. Introduction of namespaces

xmlns:wf= "Clr-namespace:system.windows.forms;assembly=system.windows.forms" xmlns:wfi= "Clr-namespace: System.windows.forms.integration;assembly=windowsformsintegration "

B. Control invocation

<Width= "$"  Height= "  Background" = "White"  >    <x:name= "panelsignature"/> </ Wfi:windowsformshost >

C. Description

A. There are careful child shoes will find that the front of the windowsformhost do not have to use the windowsformsintegration corresponding name (I give the name is WFI, please feel free) to restrict, XAML only import System.Windows.Forms namespace is also can , but in order to be more clear about the origin of the Windowsformhost (under which namespace in which assembly), I would recommend the notation for importing namespaces.

B. There may be children's shoes after adding a reference, proceed to the encoding work in XAML, and then find that the VS does not correct smart hints. I recommend that you add a reference to build (compile) so that the compiler knows that a new DLL has been imported and that the smart hints will work.

3) Logic Code

var hwnd = Panelsignature.handle;

WinForm this way. Getting a handle to a control is simple, just one line of code. Look at the effect:

Yes, not the same. O (∩_∩) o

4. Tear Time

Completion of the signature board this task took two days, the first day to write the InkCanvas version, the next day completed the current company adopted this version. Take a test first:

There are children's shoes may ask: How not to write "test" word, or "Hello world" ... I said I was quite excited when I finished this function, and I wrote this line in a trembling hand with an electronic signature pen, and then sent it to the Goddess in mind ... When I left the company that night pouring rain, my heart was blue ('? ') )

Finally, I wish you a happy Labor Day, I believe that every effort will not be disappointed!!

"WPF" Learning Notes (ii)--still an electronic signature board

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.