I got a hard time until I (with the help of Google) found out how to create User Controls for the .Net CF and how to integrate these user controls into Visual Studio (with a nice icon in the Toolbox and the right appearance in the Visual Studio Designer). I want to summarize the most important points here… Maybe this helps to save someones time.

1. Create a User Control

First of all start a Smart Device Project in Visual Studio. In the new project you’ll find a User Control which one you can adapt to your needs (adding other controls, painting etc.). You’ll find a lot of tutorials in the net explaining this part.

2. Create a Toolbox Icon

When you include the dll created in Step 1, you’ll find a cog-wheel as Toolbox Icon for your Control. To change this create a 16×16 pixel bitmap (*.bmp) with a color depth of 24 first. Add the bitmap to a folder hierarchy that matches the namespace of your User Control. For instance, your User Control is defined in the namespace this.is.my.namespace, then your folder hierarchy may looks like this:

  • this
    • is
      • my
        • namespace (here goes your Toolbox Icon)

Finally, set the Build Property for the icon to Embedded Resource.

3. Create Design Time Attributes

Add a Design Time Attribute file (*.xmta) file to your project. Add the following code to your file:

<?xml version="1.0" encoding="utf-16"?>
<Class Name="YourNamespace.YourControl">
<Description>Shows some state of a device.</Description>

4. You may need to restart Visual Studio, so it can adapt the changes to the User Control configuration.

If you don’t find your User Control having a nice icon or causing exceptions and error check the following things:

  1. You may add

    to your User Control. When you debug the User Control you should find your bitmap in the array returned by the function having the correct namespace of your User Control mentioned in the file identifier.

  2. Check the project configuration and adapt the Standard Namespace if necessary.
  3. If you use device specific DLLs, don’t forget to surround them by a try-catch-clause, so invocation of DLL functionality does not cause any exceptions when the designer tries to create an object on a form.


PS. Feedback appreciated!