Welcome!

Symbian Authors: Jack Newton, Kevin Benedict, Matthew Lobas, Shelly Palmer, RealWire News Distribution

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Creating Controls for.NET Compact Framework in Visual Studio 2005

Learn to build the building blocks of mobile UI

This DesignTimeAttribute.xmta file is where Visual Studio 2005 stores design-time attributes for custom control. This file can be directly edited in XML editor. It has intellisense support so you can find out the full list of design-time attributes.

Compile the project and go to the project output folder. There will be three files:

  • SignInControl.dll
  • SignInControl.pdb
  • SignInControl.Smartphone.asmmeta.dll

You should already be familiar with SignInControl.dll and SignInControl.pdb. What is SignInControl.Smartphone.asmmeta.dll? This is design-time metadata assembly; it is where the design-time attributes reside. Design-time metadata assembly is used by Visual Studio 2005 during design-time. If you run ildasm.exe on it, you will find the Description and Category attributes that we just created.

Now the description and category issue is solved. What about the second one? How to control when to generate code for properties? It can be solved by DefaultValue design-time attribute. Or, it can be done by adding a ShouldSerializeXXX method to the custom control. ShouldSerializeXXX method is very easy to create and it provides more flexibility. Open SignInControl.cs in code editor and add the following code:

private bool ShouldSerializeUserName() {
    return textBox1.Text != "";
}
private bool ShouldSerializePassword() {
    return textBox2.Text != "";
}

private bool ShouldSerializeAnimationMode() {
    return animationMode != AnimationMode.None;
}

private bool ShouldSerializeAnimationImages() {
    return animationImages != null;
}

ShouldSerializeXXX method is invoked by Visual Studio 2005 during design-time to check if property’s value should be persisted into code. By implementing this method for a property, custom control can decide whether a property value should be persisted or not.

Adding Device-Specific Functionalities
SignInControl is intended to be used by Smartphone users. If the password is required to be all numerical (such as PIN number), people using the application will have a hard time because by default Smartphone TextBox takes all characters, both text and numbers. For this reason, I decided to add a “number only” mode to my SignInControl to help the users.

After defining a PasswordInput-Mode enum type with two values – Regular and NumberOnly – I created textBox2.GotFocus event handler (textBox2 is the TextBox for input password) as textBox2_GotFocus and added the code in Listing 3 to SignInControl.cs



This code adds a new property, PasswordInputMode, to SignInControl. If the input mode is set to NumberOnly, whenever textBox2 (the TextBox control for taking password) receives focus, an EM_SETINPUTMODE windows message will be sent to set the input mode to number-only mode. P/Invoke (Platform Invoke) is used here to find the native window handle and send windows messages.

This custom control will work as expected in a Smartphone device or emulator. However, after this change, SignInControl will be replaced by an empty placeholder in the designer as in Figure 7.

This is because Visual Studio 2005 detects the existence of P/Invoke code in the custom control. P/Invoke code is mostly specific to device OS and may fail during design-time when running on a desktop computer. Custom controls with P/Invoke, or referencing assemblies containing P/Invoke, are treated as Device Specific.

To prevent issues from happening during design-time, by default Visual Studio replaces device-specific custom control with a placeholder control in designer. This is why the empty placeholder control appears.

To solve this issue, the key is to:

  1. Make the custom control desktop compatible. Usually this means do not execute the device-specific code during design-time. Or, if executing them cannot be avoided during design-time, handle the error gracefully.
  2. Add DesktopCompatible(true) design-time attribute to the control.

In the case of SignInControl, I need to make sure the textBox2.GotFocus event handler is not being executed during design-time. Luckily this is already done: a TextBox under design mode cannot receive focus. What’s left is to add the DesktopCompatible (true) attribute to mark SignInControl compatible with desktop design-time.

As mentioned earlier, class designer is the best way to add design-time attributes. Open class designer, select SignInControl, and open the editor for Custom Attributes. Type in:

DesktopCompatible(true)

Now compile and reopen the form designer. The custom control is back to the designer!

More Design-time Features You Can Use
There are lots of design-time features in Visual Studio 2005. Some common ones are:

  • Use BrowsableAttribute to hide a property or event from property browser during design-time.
  • Use DesignerSerializationVisibilityAttribute to specify how a property’s value is persisted into code.
  • Use DefaultValueAttribute to specify a default value for the property.
  • Specify an Editor with EditorAttribute. An Editor can customize the property-editing experience during design-time.
  • Specify a Designer with DesignerAttri-bute. A Designer can add context menu options during design-time; it can re-place a property (property shadowing) during design-time, and can change
  • the custom control’s behavior during design-time.

Hope this article gives you some understanding about how to create a .NET Compact Framework custom control in Visual Studio 2005 and provide design-time support. Please take a look at the SignInControl sample used in this article (source code is available by viewing this article online at http://dotnet.sys-con.com/). If you have further questions and comments, please contact our team blog (http://blogs.msdn.com/vsdteam) or e-mail me at [email protected].

More Stories By Xin Yan

Xin Yan has been a software design engineer at Microsoft for over 7 years. He works on Visual Studio developer tools platform team.

Comments (4) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Jay Dixit 10/11/07 07:07:23 AM EDT

Hi truly a great article but i am new for it and just have some queries.
1. I don't understand AnimationMode.
2. I don't understand PasswordInputMode.
As per the understanding i have gone throught the detail and implemented the same. After leaving AnimationMode and PasswordInputMode, i have run the code on emulator but i am not able to see the effect.

Please help me for this.

Jacques Herweijer 02/05/07 03:23:28 PM EST

Hi great article, I completely understand the usercontrols now in a few minutes, its better than reading a book about it ! That however leaves me with 2 unanswered questions hope you can answer them.

My first question is, How can I access the properties of the labels as soon as the usercontrol is used on a form, so I can change the Text property depending on the form I am using it on, or do I have to create a new usercontrol that inhertis your example for each label Text I want to use and drop that one on my form. I think this is very much work for just setting a label.

And then my second one, How can I add controls to the usercontrol when I put it on my form ? For example if I wanted to add a button to the usercontrol when it is on my form but not in de usercontrol class itself (like a panel can contain controls) in Design-time ofcourse.

Hope you can and be willing to give me an answer because I cannot find these answers anywhere. I think its hard to search the web when some functionallity is not available for Smart Device projects.

Anyway Great article that give me a head start.

.NET News Desk 07/28/05 02:49:36 PM EDT

Creating Custom Controls for Microsoft .NET Compact Framework in Visual Studio 2005
Visual Studio 2005 fully supports creating custom controls in .NET Compact Framework. In addition, custom control developers can create a great design-time experience for custom control users. Design-time support makes it easier for developers to use custom controls in Visual Studio 2005 Smart Device projects.

.NET News Desk 07/28/05 02:49:30 PM EDT

Creating Custom Controls for Microsoft .NET Compact Framework in Visual Studio 2005
Visual Studio 2005 fully supports creating custom controls in .NET Compact Framework. In addition, custom control developers can create a great design-time experience for custom control users. Design-time support makes it easier for developers to use custom controls in Visual Studio 2005 Smart Device projects.

@ThingsExpo Stories
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend @CloudExpo | @ThingsExpo, June 6-8, 2017, at the Javits Center in New York City, NY and October 31 - November 2, 2017, Santa Clara Convention Center, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
SYS-CON Events announced today that EARP Integration will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. EARP Integration is a passionate software house. Since its inception in 2009 the company successfully delivers smart solutions for cities and factories that start their digital transformation. EARP provides bespoke solutions like, for example, advanced enterprise portals, business intelligence systems an...
SYS-CON Events announced today that WineSOFT will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Based in Seoul and Irvine, WineSOFT is an innovative software house focusing on internet infrastructure solutions. The venture started as a bootstrap start-up in 2010 by focusing on making the internet faster and more powerful. WineSOFT’s knowledge is based on the expertise of TCP/IP, VPN, SSL, peer-to-peer, mob...
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, will motivate why realizing the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insigh...
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @CloudExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
SYS-CON Events announced today that Carbonite will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Carbonite protects your entire IT footprint with the right level of protection for each workload, ensuring lower costs and dependable solutions with DoubleTake and Evault.
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs oft...
SYS-CON Events announced today that Cloud Academy will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud computing technologies. Ge...
DevOps at Cloud Expo – being held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real r...
SYS-CON Events announced today that Outscale will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Outscale's technology makes an automated and adaptable Cloud available to businesses, supporting them in the most complex IT projects while controlling their operational aspects. You boost your IT infrastructure's reactivity, with request responses that only take a few seconds.
As cloud adoption continues to transform business, today's global enterprises are challenged with managing a growing amount of information living outside of the data center. The rapid adoption of IoT and increasingly mobile workforce are exacerbating the problem. Ensuring secure data sharing and efficient backup poses capacity and bandwidth considerations as well as policy and regulatory compliance issues.
The 21st International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Digital Transformation, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend @CloudExpo | @ThingsExpo, June 6-8, 2017, at the Javits Center in New York City, NY and October 31 - November 2, 2017, Santa Clara Convention Center, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that Interoute has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Interoute is the owner operator of Europe's largest network and a global cloud services platform, which encompasses over 70,000 km of lit fiber, 15 data centers, 17 virtual data centers and 33 colocation centers, with connections to 195 additional partner data centers. Our full-service Unifie...
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs ofte...
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @ThingsExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
SYS-CON Events announced today that Hitachi Data Systems, a wholly owned subsidiary of Hitachi LTD., will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City. Hitachi Data Systems (HDS) will be featuring the Hitachi Content Platform (HCP) portfolio. This is the industry’s only offering that allows organizations to bring together object storage, file sync and share, cloud storage gateways, and sophisticated search and...
Existing Big Data solutions are mainly focused on the discovery and analysis of data. The solutions are scalable and highly available but tedious when swapping in and swapping out occurs in disarray and thrashing takes place. The resolution for thrashing through machine learning algorithms and support nomenclature is through simple techniques. Organizations that have been collecting large customer data are increasingly seeing the need to use the data for swapping in and out and thrashing occurs ...