advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Download the Custom User Control source code for this article.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
 

.NET Building Blocks: Custom User Control Fundamentals

Find out the gritty details required to create, test, use, inherit, install, and distribute .NET User Controls of all types. 


advertisement
ith the .NET framework, you can build Windows Forms applications (those that run on your local machine) or Web Form applications (those that run in your browser). A Windows Form is simply a container for a collection of controls—buttons, fields, drop-down boxes, selectors, and so forth—that users may interact with and manipulate. This article discusses the fundamentals of such controls, including both how to consume them at design time and, in particular, how to create your own custom controls. It is not nearly as daunting as you might think at first glance to create custom controls; after you learn the principles laid out here, you will be able to make your own library of building blocks, adding your controls to the Visual Studio Toolbox right alongside the standard ones.


What You'll Cover
  • Types of custom controls. You will learn about the different types, when to use them, and how to create them.
  • Testing custom controls. Visual Studio provides a runnable wrapper—a remarkable tool called the "UserControl Test Container."
  • Incorporating custom controls into your applications. Understand the logistics of control libraries, loading them into your Toolbox, and manipulating them.
  • Augmenting custom controls. With some handy tips you can integrate your controls seamlessly into Visual Studio.
What You Need
  • Visual Studio 2008 or VS2005
  • C# 3.0 or 2.0 (there are a couple of spots you'll need to adjust if using C# 2.0 in VS2005)
  • .NET Framework: 2.0 or higher

A Simple Composite User Control
In this first exercise, you will build "ClockControl," a simple digital-clock timer control. The basic example comes from the MSDN documentation "Walkthrough: Authoring a Composite Control with Visual C#," because it serves as a good launching point for further discussion. The MSDN walkthrough provides step-by-step instructions to create this user control, and is a useful aid if you don't have much experience with controls, so I won't duplicate those instructions here. The version of the example you'll see here deviates from the walkthrough both in component naming and in coding; it's simpler and easier to comprehend. Also, rather than having to build the example, you can download the finished code, which you can then load and run immediately.

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



advertisement