By Xin Yan | Article Rating: |
|
July 29, 2005 01:45 AM EDT | Reads: |
132,068 |

One of the new features in Visual Studio 2005 (VS2005) is easier custom control development for .NET Compact Framework. This article is about how to use Visual Studio 2005 to create custom control for .NET Compact Framework and provide design-time support.
Introduction to Custom Control
A Windows Forms custom control is a class that derives directly or indirectly from System.Windows.Forms.Control or System.Windows.Forms.
UserControl. Using custom control technology, developers can easily create powerful, reusable and redistributable Windows Forms controls.
There are three common custom control scenarios:
- Combine existing controls to author a composite control. In this case, the custom control should derive from System.Windows.Forms.UserControl.
- Extend an existing control to add to its functionality. In this case, the custom control should derive from the existing control, such as System.Windows.Forms.TextBox.
- Author a control that doesn’t depend on existing WinForm controls. In this case, the custom control should derive from System.Windows.Forms.Control.
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.
Usually, building a custom control for .NET Compact Framework consists of two steps:
- Code the custom control
- Add design-time support
In this article I am going to illustrate these steps by building a .NET Compact Framework custom control in Visual Studio 2005. The custom control is for sign-in forms and will look like Figure 1 on a Smartphone device. It is called SignInControl. Developers can utilize this custom control to implement a consistent sign-in experience for their apps. It has the following features:
- Can take user name and password input
- Provides animation functionality
- Can be easily used in Visual Studio 2005 designer
- Supports numeric input mode to help Smartphone users
To follow the article, you will need Visual Studio 2005 Beta 2 and Windows Mobile 5 Smartphone SDK.
Code the Custom Control
SignInControl uses Label and TextBox controls to take user input, and PictureBox to display the animation. Thus it should derive from UserControl.
The first step is to create a Visual Studio Smart Device project. Visual Studio 2005 has many Smart Device project types to choose from. In this example I am going to create a C# SmartPhone Windows Mobile 5 (code named Magneto) Control Library project called SignInControl (see Figure 2).
After creating the project, rename the UserControl1.cs to SignInControl.cs. To protect my custom control assembly from tampering, I also signed my assembly with a strong name key file (right click on the project in the solution explorer, select “Properties,” and click on “Signing” tab). Now I am ready to implement my custom control.
Go to the designer and drop two Label controls, two TextBox controls, one PictureBox control, and one Timer component. When doing this, notice the designer automatically displays snap-line to help aligning the controls. Set the Label controls to have proper text, and set the PasswordChar property of the password TextBox to “*.” Figure 3 is a screenshot of SignInControl in the designer.
Two properties should be added to SignInControl to give developers access to the user name and password entered. Their implementation simply gets or sets the Text property value on the corresponding TextBox controls.
Animation support is provided by the use of Timer and PictureBox. Add a Timer object to SignInControl, set its Interval property to 1000 (one second), and double click it to generate Timer.Tick event handler. The Timer object will raise an event every second. The PictureBox control’s image will be refreshed on each tick to achieve an animation effect.
The images for animation are set in AnimationImages property using ImageList. An AnimationMode property is provided so that developers can turn animation on or off. After adding the above implementation, SignInControl.cs looks like Listing 1.
Published July 29, 2005 Reads 132,068
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
![]() |
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. 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 |
![]() |
.NET News Desk 07/28/05 02:49:30 PM EDT | |||
Creating Custom Controls for Microsoft .NET Compact Framework in Visual Studio 2005 |
- iPad3 vs Windows 8 - and the Winner Is...Cloud
- Cisco Unveils Visual Collaboration Solutions in the Post-PC Era, Extending the Reach of TelePresence With New Mobile-to-Immersive Offerings
- Eleven Reasons Why Windows Phone Will Overtake Android
- Windows Azure Overview Part 4: Security
- Agile Development & Enterprise Architecture Practice – Can They Coexist?
- Eleven Tips for Successful Cloud Computing Adoption
- System Center Virtual Machine Manager 2012 as Private Cloud Enabler
- The Web – Changing the Way We Work
- Book Review: Decision Management Systems
- EE Times and EDN Announce the 2012 UBM Electronics ACE Award Winners
- User Group Malaise?
- Closer Look at One NoSQL Database – MongoDB
- iPad3 vs Windows 8 - and the Winner Is...Cloud
- Cisco Unveils Visual Collaboration Solutions in the Post-PC Era, Extending the Reach of TelePresence With New Mobile-to-Immersive Offerings
- Eleven Reasons Why Windows Phone Will Overtake Android
- Windows Azure Overview Part 4: Security
- Agile Development & Enterprise Architecture Practice – Can They Coexist?
- Eleven Tips for Successful Cloud Computing Adoption
- System Center Virtual Machine Manager 2012 as Private Cloud Enabler
- The Web – Changing the Way We Work
- Book Review: Decision Management Systems
- EE Times and EDN Announce the 2012 UBM Electronics ACE Award Winners
- Working with Microsoft Security Tools
- Parallels Continues to Lead the Hosting and Cloud Services Enablement Industry, with a Sweeping Introduction of New Software and Services, an Expansion of its Partner Ecosystem and the Latest Research on SMB Cloud Buying Behavior
- Google Maps and ASP.NET
- Converting VB6 to VB.NET, Part I
- How to Write High-Performance C# Code
- Crystal Reports XI & How It Has Changed
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- Programmatically Posting Data to ASP .NET Web Applications
- Implementing Tab Navigation with ASP.NET 2.0
- AJAX World RIA Conference & Expo Kicks Off in New York City
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- ');
for(i = 0; i < google_ads.length; ++i)
{
document.write('
- ');
document.write('' + google_ads[i].line1 + '
'); document.write('' + google_ads[i].visible_url + '
'); document.write(google_ads[i].line2 + ' ' + google_ads[i].line3); document.write(' ');
}
document.write('