IntelliProg - Articles & FAQ

 Mailing List

Enter your email address in the box below to join our mailing list:


Design-time functionality for custom controls in Compact Framework and SDE.


Alex Yakhnin, eMVP

Windows CE Program Manager

IntelliProg, Inc.


September 2002

Applies to:
    Microsoft® .NET Compact Framework
    Microsoft Windows® CE

Summary: Techniques to add design-time functionality to a custom controls in Compact Framework and Smart Device Extensions. Includes downloadable source code.


Download the source code for the article



It’s all about Control

Working the Steps






Design-time architecture in .NET Framework and Visual Studio.NET is extendable and customizable set of attributes and interfaces allowing component developers easy to implement design-time functionality. It consists of Custom Attributes, Type Converters and Custom Designers [1].

In order to make a custom control to appear in the toolbox of a visual designer and to be dragged and dropped on to a design surface in .NET Framework you would derive your control from System.ComponentModel.Control or System.ComponentModel.Component which implement System.ComponentModel.IComponent interface. This path will not work in .NET Compact Framework and SDE, because the System.ComponentModel.IComponent interface is missing from the Compact Framework runtime assemblies. A lot of changes have been done to reduce the size of the framework and improve its performance and execution speed.

But having design-time functionality for your controls in .NET Compact Framework is still possible!

It’s not as easy and straightforward as it is for a desktop version of the .NET and will require a few additional steps to complete, but you should be able to contrive design-time functionality in your own custom controls by following the steps I outline bellow.


It’s all about Control.


I’ve chosen to base this walkthrough on the sample Clickable Label control that have been posted on the .NET Compact Framework Newsgroup.  The sample shows creation of the Label control by deriving it from System.Windows.Forms.Control. It’s a comprehensible and clear-cut illustration of creating an owner-drawn custom control.  As you should know, “owner-drawn” means that a control developer ought to be fully responsible for painting and rendering of the created control. 

The hart of all owner-drawn controls is OnPaint event where all the drawing is happening. In this case the DrawString and DrawRectangle methods of the Graphics object are used to draw the text and a border of the label:


protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)


Graphics graphics = pe.Graphics;

      Pen pen = new Pen(Color.Black);

      SolidBrush brush = new SolidBrush(ForeColor);

      Font font = new Font(this.fontName, this.fontSize, 


      SizeF s;


      if (this.BorderStyle == BorderStyle.FixedSingle)

            graphics.DrawRectangle(pen, 0, 0, this.Width - 1,

                                                 this.Height - 1);

      else if (this.BorderStyle == BorderStyle.Fixed3D)

            graphics.DrawRectangle(pen, this.ClientRectangle);


      s = graphics.MeasureString(this.Text, font);

      switch (this.textAlignment)


      case ContentAlignment.TopCenter:

            graphics.DrawString(this.Text, font, brush, (this.Width – 

                    s.Width) / 2, (this.Height - s.Height) / 2);


      case ContentAlignment.TopLeft:

            graphics.DrawString(this.Text, font, brush, 2, (this.Height

                                              - s.Height) / 2);


      case ContentAlignment.TopRight:

            graphics.DrawString(this.Text, font, brush, this.Width –

                      s.Width - 2, (this.Height - s.Height) / 2);







      if (labelPaint != null)

            labelPaint(this, pe);






Creation of owner-drawn controls is a separate subject by itself requiring a whole article or even a set of articles devoted to it, so in the course of this editorial I would like to concentrate on how-to change the code of the Clickable Label control to make it to behave as any other built-in SDE controls: to be shown in the Toolbox, dragged and dropped on the design surface, to be able to change properties and events in a property browser.




Working the Steps.


Even though the IComponent interface is missing from the runtime versions of the .NET CF assemblies, Microsoft has included a special design-time versions of these assemblies that contain full implementation of the design-time architecture:





Note   These design time DLLs should be installed under your Compact Framework SDK path in a special design folder. For example, on my machine these DLLs are located in


C:\Program Files\Microsoft Visual Studio .NET\CompactFrameworkSDK\v1.0.3300\Windows CE\design directory


Having a set of design-time assemblies means that our Label control will have to be recompiled against these special assemblies and a design-time version of the Label control added to the VS IDE Toolbox.


Step 1 -  System.CF.Design.RuntimeAssemblyAttribute.


Let’s add the following line just before declaration of the Label’s namespace:



[assembly: System.CF.Design.RuntimeAssemblyAttribute("LabelControl, Version=, Culture=neutral, PublicKeyToken=null")]


namespace LabelControl


      public class Label : Control


. . . .

. . . .


We have just added a conditional compilation statement that uses the NETCFDESIGNTIME define and System.CF.Design.RuntimeAssemblyAttribute to let Visual Studio know which design time assembly is associated with which runtime assembly. This attribute accepts the full strong name of the runtime. It is important to have this parameter to be exact and correspond to the name and version of your runtime assembly.


WARNING:  When using Visual Studio to build your runtime control, your fully qualified assembly name changes EVERY TIME you build (the minor version number is updated), This default behavior would require you to update your designer after every build as well. To overcome this problem, you should open the AssemblyInfo.cs file and instead of:

[assembly: AssemblyVersion("1.0.*")]

specify an exact version numbers:

[assembly: AssemblyVersion("")]



Step 2 - Change any platform specific code.


If there is any code in the control that is specific to the device platform it will definitely not work in the regular .NET framework.  This includes use of Framework classes that aren’t available on the desktop .NET framework, or using native code functions on the platform.  You can use the NETCFDESIGNTIME define to conditionally include different code for run-time and design-time. The sample below shows how you would call the PlaySound native function during design time and then runtime.



       [DllImport("winmm.dll", EntryPoint="sndPlaySoundW")]

       private static extern int PlaySound(String szName, uint uiSound);


       [DllImport("coredll.dll", EntryPoint="sndPlaySoundW")]

       private static extern int PlaySound(String szName, uint uiSound);



Since in the Label control we are working with, we don’t have code specific to the device, we will skip this step.


Step 3 - Adding Custom Designer Attributes.


By default your control will inherit its design time attributes from its base classes, so you don’t need to add any designer attributes to have your designer work.  But if you would add a custom property or would like to override the base class designer attributes you would specify them explicitly in your control. Generally speaking, all design-time attributes that available for the desktop, also available for your use in SDE. [2]


The Clickable Label control includes implementation of the TextAlignment property that is not a part of the base class System.Windows.Forms.Control we inherited from, so we will add the following design-time attributes before the declaration of the TextAlignment property:






   System.ComponentModel.Description("Specifies the alignment of text.")



public ContentAlignment TextAlignment


   get {return this.textAlignment;}

   set {

            this.textAlignment = value;

            //Force to repaint





In this code fragment, the CategoryAttribute attribute enables the property browser to display the TextAlignment property in the Alignment category. The DescriptionAttribute attribute allows the property browser to provide a brief description of the property when a user clicks on it.





Step 4 – Compile the control’s source code against SDE designer libraries.


Now it’s time to build a design-time version of Clickable Label. To do that we will use a batch file called BUILDDES.BAT.  It’s a simple batch file that uses the command line C# compiler (csc.exe) and takes the following parameters:


<Library Name>   

Output library/control name.  It will add “Design.” prefix to the start of the control’s name.

<Source File1>  <Source File2>…

The source files that need to be compiled.

<Compiler Flags>

- Optional compiler flags




BUILDDES.BAT <Library Name> <File 1> ... <File n> <Flag 1>... <Flag n>




BUILDDES.BAT CustomControls.ImgView.dll ImgView.cs /o



In our case the command line should look like that:


BUILDDES.BAT LabelControl.dll Label.cs /o


In order to execute this batch file you will need to copy it into the project directory along with System.CF.Windows.Forms.dll, System.CF.Design.dll and System.CF.Drawing.dll from “…CompactFrameworkSDK\v1.0.3300\Windows CE\design\” directory.


The output of this command would be the design-time version of the Clickable Label:






Step 5 – Installing the design-time control into the Smart Device Extensions.


In order to have the Smart Device Extensions recognize the control library, we need to install/copy the runtime and design time piece into the SDK directories.


We copy runtime file LabelControl.dll from our project’s \bin subdirectory into the “...\CompactFrameworkSDK\v1.0.3300\Windows CE” directory.  For the default install, this will be


C:\Program Files\Microsoft Visual Studio .NET\CompactFrameworkSDK\v1.0.3300\Windows CE


We also copy our design time file Design.LabelControl.dll into the “...\CompactFrameworkSDK\v1.0.3300\Windows CE\designer”, for the default install this will be


C:\Program Files\Microsoft Visual Studio .NET\CompactFrameworkSDK\v1.0.3300\Windows CE\Designer


Now, we can add the design-time version the Visual Studio.NET Toolbox by right-clicking on ‘Device Controls’ tab it and selecting ‘Customize Toolbox…’ menu item:



Just browse to the ...\CompactFrameworkSDK\1.0.3300\Windows CE\Designer directory and select the design-time version of our assembly on the next dialog and we should have the new control to appear in the Toolbox.



It is possible to automate the compiling process of the design-time version of the control by utilizing the ‘External Tools…’ feature of the Visual Studio IDE.  Here are the steps that should be done to have a menu item in your IDE:

  1. Copy BUILDDES.BAT file into the “...\CompactFrameworkSDK\v1.0.3300\Windows CE\bin\” directory.
  2. Go to the “Tools\External Tools…” menu in the Visual Studio IDE and click ‘Add’ button to add a new tool:


  1. Give it a descriptive name of your choice (I named it ‘Design-Time Batch’) and browse to the BUILDDES.BAT location in the “...\CompactFrameworkSDK\v1.0.3300\Windows CE\bin\” directory
  2. In the Arguments setting I have put:

$(TargetName)$(TargetExt)  $(ItemPath)""

And for InitialDirectory my setting is:

C:\Program Files\Microsoft Visual Studio .NET\CompactFrameworkSDK\v1.0.3300\Windows CE\Designer\

     5.  Check in the ‘Use Output Window’ check box to enable output from the batch file execution into IDE’s Output Window.





Now to compile a design-time version of your control you would just select your newly added tool from the menu.





In this article I have shown you the steps required to create a design-time version of the custom control. By utilizing the design-time infrastructure included in the special design-time .NET Compact Framework assemblies, control authors and creators will be able to create a more powerful and user-friendly controls and components.


Disclaimer: Information contained in this article is related to the beta version of .NET Compact Framework and Smart Device Extensions and may be changed by the time commercial version is released.




[1] Design-time Architecture

[2] Design-time Attributes for Components

[3] Make Your Components Really RAD with Visual Studio .NET Property Browser





Articles for developers that have been written by Alex Yakhnin:

Articles on MSDN web site:

Using the Microsoft .NET Compact Framework MessageWindow Class

Creating a Microsoft .NET Compact Framework-based Animation Control

Creating a Microsoft .NET Compact Framework-based Process Manager Application

How to Create a Microsoft .NET Compact Framework-based Image Button

DevBuzz web site:

Saddling the HTML View Control from eVB.

Saddling the HTML View Control Part II / Catch Those Messages.

See the articles on the usage of the MessageCE control at Microsoft Mobile web site: 

Capture Windows Messages Using the MessageCE Control.

Tap-and-Hold Confirmation in eMbedded Visual Basic.

You can read a review of the AtlasCE on FoxPop.




Copyright © 2002 IntelliProg,Inc.
Web Development by: BorderNet Technology