Chapter 21. Creating Your Own Controls


You will learn about the following in this chapter:

  • How to design a control

  • How to add properties to a control

  • How to add methods to a control

  • How to process control events

  • How to test a control

At the time of this writing, more than three dozen Windows Forms controls are being shipped with Visual Basic .NET. If you include other controls that are not used with Windows forms, such as Web controls, the count increases to more than 50 controls. Everything you need is there for you on the toolbar, right? Well, not quite. No matter how many controls are bundled with Visual Basic .NET, each programming task has little nuances of difference that make programmers wish for controls that do this or that. Alas, if the only tool you have is a hammer , pretty soon every problem starts to look like a nail.

You need a variety of tools to do a job right, and Visual Basic .NET gives you a pretty robust selection. If you really do have a problem that one of the Visual Basic .NET tools can't even come close to solving, however, you can check the Visual Basic .NET magazines or the Internet for an appropriate tool. Purchasing off-the-shelf controls is often a cost-effective and smart way to program a solution.

Still, there are a lot of situations in which the Visual Basic .NET tool set comes close to what you need, but it's not quite a perfect fit. The circumstance is not as bad as "round hole, square peg" situation; it's more like a "round hole, oval peg" problem. This chapter shows how to turn oval pegs into round ones; that is, it shows you how to craft your own custom controls.

You can approach the problem of crafting your own custom controls by using any one of three general methods:

  • You can add whatever functionality an existing control is lacking via inheritance.

  • You can combine several existing controls into a single control to extend their functionality.

  • You can build your own control from the ground up.

This chapter shows how to combine the first two methods to build a new control. You'll learn how to build a custom control from three text box controls. Inheritance provides the lion's share of the new control's functionality. When you understand the basics of building a custom control, you will find it pretty straightforward to build new controls from scratch.



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net