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… [Continue Reading]
Building Custom Windows Controls
Enhancing Existing Controls
The simplest type of custom Windows control you can build is one that enhances the functionality of an existing control. Fortunately, they’re the most common types of custom controls, and many developers have their own collections of “enhanced” Windows controls. The Windows controls are quite functional, but you won’t be hard-pressed to come up with… [Continue Reading]
Adding Functionality to Your Custom Control
As you can see, it’s quite trivial to create a new custom control by inheriting any of the built-in Windows controls. Of course, what good is a control that’s identical to an existing one? Let’s add some extra functionality to our custom TextBox control. Switch to the control project and view the FocusedTextBox object’s code…. [Continue Reading]
Building Compound Controls
A compound control provides a visible interface that consists of multiple Windows controls. The controls that make up a compound control are known as constituent controls. As a result, this type of control doesn’t inherit the functionality of any specific control. You must implement its properties and methods with custom code. This isn’t as bad… [Continue Reading]
Building User-Drawn Controls
This is the most complicated but most flexible type of control. A user-drawn control consists of a UserControl object with no constituent controls. You are responsible for updating the control’s visible area with the appropriate code, which must appear in the control’s OnPaint method. (This method is invoked automatically every time the control’s surface must… [Continue Reading]
Raising Custom Events
When you select the custom control in the Objects drop-down list of the editor and expand the list of events for this control, you’ll see all the events fired by UserControl. Let’s add a custom event for our control. To demonstrate how to raise events from within a custom control, we’ll return for a moment… [Continue Reading]
Designing Irregularly Shaped Controls
The UserControl object has a rectangular shape by default. However, a custom control need not be rectangular. It’s possible to create irregularly shaped forms, too, but unlike irregularly shaped controls, an irregularly shaped form is still quite uncommon. Irregularly shaped controls are used in fancy interfaces, and they usually react to movement of the mouse…. [Continue Reading]
Customizing List Controls
In this section, I’ll show you how to customize the list controls (such as the ListBox, ComboBox, and TreeView controls). You won’t build new custom controls in this section; actually, you’ll hook custom code into certain events of a control to take charge of the rendering of its items. Some of the Windows controls can… [Continue Reading]