Visual Basic.NET 2008 > Building Custom Windows Controls

Building Custom Windows Controls in Visual Basic 2008

Jump to Table of Contents

Just as you can design custom classes, you can use Visual Studio to design custom controls. The process is very similar, in the sense that custom controls have properties, methods, and events, which are implemented with code that's identical to the code you'd use to implement these members with classes. The difference is that controls have a visual interface and interact with the user. In short, you must provide the code to draw the control's surface, as well as react to selected user actions from within the control's code.

In this chapter, you'll learn how to enhance the functionality of existing controls, a common practice among developers. You've already seen in the preceding chapter how to inherit an existing class and add custom members. You can do the same with the built-in controls.

There are several methods of designing custom controls. In this chapter, we'll discuss the following:

  • Extend the functionality of existingWindows Forms controls with inheritance - The simplest type of control you can build is one that inherits an existing control. The inherited control includes all the functionality of the original control plus some extra functionality that's specific to an application and that you implement with custom code.

  • Build compound custom controls that combine multiple existing controls - A compound control provides a visible interface that combines multiple Windows controls. As a result, this type of control doesn't inherit the functionality of any specific control; you must expose its properties by providing your own code. The UserControl object, on which the compound control is based, already exposes a large number of members, including some fairly advanced ones such as the Anchoring and Docking properties, and the usual mouse and key events.

  • Build custom controls from scratch - User-drawn controls are the most flexible custom controls, because you're in charge of the control's functionality and appearance. Of course, you have to implement all the functionality of the control from within your code, so it takes substantial programming effort to create user-drawn custom controls.

  • Customize the rendering of the items in a ListBox control - To create an owner-drawn list control, you must set the DrawMode property to a member of the DrawMode enumeration and program two events: MeasureItem and DrawItem.

Get Started >>

 

Table of Contents

  1. Building Custom Windows Controls
  2. Designing Windows Controls
  3. Enhancing Existing Controls
  4. Adding Functionality to Your Custom Control
  5. Building Compound Controls
  6. Building User-Drawn Controls
  7. Raising Custom Events & Using the Custom Control in Other Projects
  8. Designing Irregularly Shaped Controls
  9. Customizing List Controls

     
 
W3computing.com Copyright 2011 All Rights Reserved
 
  Home | Useful links | Contact us