This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ??? ? P ublished on T h e O 'R e illy N e tw o rk ( h ttp ://w w w .o re illy n e t.c o m / ) ? h ttp ://w w w .o re illy n e t.c o m /p u b /a /d o tn e t/2 0 0 2 /0 3 /1 8 /c u s to m c o n tro ls .h tm l ? S ee this if y o u 're h a v in g tro u b le p rin tin g c o d e e x a m p le s Creating Custom .NET Controls with C# by Budi Kurniawan 03/18/2002 Windows programmers have a wide variety of controls to choose from in the System.Windows.Forms namespace in .NET's Framework class library. You have controls as simple as Label , TextBox , and CheckBox , as well as controls as sophisticated as the MonthCalendar and ColorDialog controls. These Windows controls are more than enough for most applications; however, sometimes you need controls that are not available from the standard library. In these circumstances, you have to roll up your sleeves and write your own. This article shows you how to develop a custom control with C# and presents a simple custom control. Before you start writing the first line of code for your custom control, you should familiarize yourself with two classes in the System.Windows.Forms namespace: Control and UserControl . The Control class is important because it is the parent class of Windows visual components. Your custom class will be a descendent of the Control class as well. Your custom controls, however, don't normally inherit directly from the Control class. Instead, you extend the UserControl class. The first two sections of this article discuss these two classes. In the final section, you'll build your own custom control, the RoundButton control. The Control Class The Control class provides very basic functionality required by classes that display information to the Windows application user. This class handles user input through the keyboard and the mouse, as well as message routing and security. More importantly, the Control class defines the bounds of a control (its position and size), although it does not implement painting. Windows forms controls use ambient properties , so child controls can appear like their surrounding environment. In this context, "ambient" means that the property is, by default, retrieved from the parent control. If the control does not have a parent and the property is not set, the control tries to determine the value of the ambient property through the Site property. If the control is not sited, if the site does not support ambient properties, or if the property is not set on the AmbientProperties object, the control uses its own default values. Typically, an ambient property represents a characteristic of a control, such as BackColor , that is communicated to a child control. For example, by default a button will have the same BackColor as its parent form....
View Full Document
This note was uploaded on 03/15/2011 for the course COMPUTER S 101 taught by Professor Dr.kim during the Spring '11 term at National Taiwan University.
- Spring '11