Professional Documents
Culture Documents
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
22
In this chapter, you will
• Get acquainted with the different types of Windows controls you can create
• Learn to build a composite control
• Understand how to license your control
• Be able to test your control
There will be times during your application development that you will need a control
that cannot be found in the Toolbox or in the component libraries. You may also dis-
cover that you often create the same combination of controls on your Windows Forms or
that you would like a particular control to exhibit extra functionality every time you use it.
All of these dilemmas can be solved by creating your own Windows Forms control.
Consider a text box control. It has a number of properties, methods, and events that
you can use when you add the control to your form. But what if you wanted that same
text box to accept only numeric input every time you used it. Instead of changing its
properties every time, you can create a new type of text box control that exhibits the be-
havior that you desire. Often in a business application, you will find that a combination
of controls is used to request a particular response from the user. Each application you
build must have the same controls added and their functionality combined. By creating
your own control that is built from the combination of these controls, you can reduce
your development time greatly. Finally, if you are in the business of creating user con-
trols for development teams, you may find that you regularly take a blank control and
draw its interface and provide its functionality from scratch.
In this chapter, we will investigate the ways you can create your own customized con-
trols. You may already be familiar with the term ActiveX controls. These were the controls
that Visual Basic programmers created and used. Microsoft has moved away from that
term, which had mostly Internet connotations, and, in order to simplify and clarify
things, now calls any component that has a visible interface a control.
At this point in your OOP career, you should not find this kind of coding to be a mys-
tery—after all, isn’t this just the same thing as building a class file in order to create reus-
able objects? The only difference here is that you build a graphical interface into the
component, with which the user can interact.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:00 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
In this section, we will consider the three types of controls and briefly describe their
use, and later we will examine the process of creating a composite control from a combi-
nation of existing controls in detail.
Microsoft will likely test your knowledge of combining existing controls into a new
single control, but we will look at all three methods individually. The combined control
is probably the control most commonly built (unless you are a control developer and
build your own from scratch).
EXAM TIP There are three ways to build your own controls: inherit from an
existing control, combine existing controls into a new control, or design and
build your own control from scratch.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:00 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
Figure 22-1 Creating a new Windows Control Library project
will explore the UserControl interface in the “Creating Composite Controls” section,
when we build controls that are made up of multiple existing controls.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:01 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
This is the inheritance line that you must change if you want to inherit from an existing
control. Our specifications state that our new control will have most of the functionality
of a regular Button control, along with our own special additions. You must, therefore,
change this line to read as follows:
By changing this line, you have effectively created a new control that derives from the But-
ton class. Your new control will have all the methods, properties, and events of a Button,
and you can modify or add to that. Save and build your project before continuing.
In order to create a new property that will allow us to set and retrieve the button’s
name, you now need to add your own property to the code—ButtonName. Start by
creating a private variable to store the new property:
1. Add a new project to your solution (File | Add Project | Windows Application).
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:01 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
EXAM TIP A control created in the Windows Control Library will not start
up a form on its own—that is why you need the new project and windows
form to test your control.
1. In Solution Explorer, right-click on the References for the new project and select
Add Reference. The Add Reference dialog box will be displayed, as shown in
Figure 22-2.
2. Select the Projects tab and choose your new control from the list.
Once you have added the reference to the control, you will see it listed under the
References heading in the Solution Explorer (see Figure 22-3).
You need to do one more thing in order to use the control from the Toolbox.
PART IV
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:01 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
2. You will be presented with the Customize Toolbox dialog box (see
Figure 22-4). Choose the .NET Framework Components tab, which lists the
installed components from the .NET Framework library. Click the Browse
button and select the location of your control.
3. Click OK.
You are now ready to build the new form. When you scroll down in the Toolbox, you
will see your own control listed there. Notice that its name is NewButton—this is why
it is very important to give your control a meaningful name from the start. Your control
now operates like any other control. Double-click on it and a default NewButton will
be added to your form (see Figure 22-5).
The final step in this process is to add the functionality that will set or retrieve the new
property. For the purposes of this demonstration, we will simply add code to the Click
event of the NewButton that will produce a MessageBox displaying the property
value:
MessageBox.Show (newButton1.ButtonName);
The following illustration shows the result of clicking on the NewButton object. Notice
that we set the property of the ButtonName during program design (look at Figure 22-5),
and the property is retrieved through the Get in the property procedure.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:01 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
ate a new control. The approach just presented of extending an existing control allows
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:02 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
you to derive your control from a base control, maintaining all the properties, methods,
and events of the base class. It also allows you to add to the original functionality or to
override it.
EXAM TIP Use these next two points to determine whether to extend an
existing control or build a new one.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:02 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
The UserControl Class
Before we go into the details of creating a new control based on existing controls, we
need to examine the UserControl class. Every control inherits from System.Win-
dows.Forms.UserControl. You can think of the UserControl class as similar to
the System.Windows.Forms.Form class—the Form acts as a container for the visual
components of your application, and the UserControl acts as a container for the con-
trols that you wish to combine into one.
There is an extensive list of properties, methods, and events associated with the
UserControl class that provide the basic functionality of your new control:
This is just a short list of the properties, methods, and events that are part of any com-
posite control. You can find the complete listing of control behavior in the help docu-
ments attached to Visual Studio .NET. Most of the behavior is inherited from the
Control class from which UserControl is derived.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:03 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
EXAM TIP A control never functions on its own. A control must exist within
a hosting application and does not execute independently.
Before we look at how these controls are built, try to keep in mind that a composite
control has two different design-time phases. The first phase is when the control itself is
designed, and this is when the developer works with the properties of the controls on
the UserControl. The second design-time phase is when the developer places the
composite control on a new form. At that point, the developer has access to those prop-
erties, methods, and events that the control developer has exposed.
EXAM TIP The controls that make up the composite control are called the
constituent controls. For example, if you create a control that has a Label and
a Timer, the Label and Timer are constituent controls. The new control
built from the combination of the two is called the composite control.
EXAM TIP Properties, methods, and events of the constituent controls are,
by default, hidden from the user of the composite control.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:03 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:04 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
TIP Set the size of the UserControl to be large enough to just hold the
constituent controls. Remember that the UserControl will be a control in
the Toolbox, and it will be added to another developer’s project.
In the StudentValidate example, you could set the ReadOnly property of the stu-
dent name text box to True, since you don’t want to allow the user to initially type into the
text box. This text box should act as a display only. You can also add any additional prop-
erties to your new control as we did earlier in the chapter for a simple extended control:
1. In the code editor, add the private variables for the properties.
2. Create the property procedures.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:04 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
Figure 22-7 The StudentValidate control
EXAM TIP Always use properties for your controls (instead of public
variables)—the Visual Studio .NET designer program will only display
properties, not variables.
In the next section, “Exposing Properties of the Constituent Control,” we will exam-
ine the code to not only add new properties but also to expose the existing properties of
the constituent control—remember, by default, they are hidden from the user of your
control.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:05 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
All-In-One
screen / MCAD/MCSD
/ MCSD Visual
Visual
C#C#
.NET
.NET
Certification
Certification
All-in-One
All-in-One
Exam
Exam
Guide
Guide
/ Rempel
/ Rempel
& Lind
& Lind
/ 222443-6
/ 222443-6
/ Chapter
/ Chapter
22
22
This CheckBox should remain invisible until the student number has been validated
since we don’t want the user to have access to it until the validation is performed. To
accomplish this, you just need to create a public property that exposes the constituent
control’s Visible property:
On a request to set the Visible property of the CheckBox called cbValid, this
simple code segment will reverse the current value. Obviously, in a sophisticated appli-
cation, the code would be more extensive. For our purposes, though, we must expose it
in this manner so the user of the StudentValidate control (who could be another
developer) can set the Visible property. This is what encapsulation is all about—users
never need to know how the Visible property is set; they just need to know that they
can use it.
You can also simply expose a constituent’s property without any extra coding:
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:05 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
This is the easiest way to allow a user of the control access to a constituent property.
You can also add properties as we did for our extended control, NewButton. Add
the private variable declaration and then create the public get and set to access the
private data:
PART IV
var = value;
}
}
EXAM TIP Remember that you can add in all the functionality that is
required within the get and set code blocks. This is the value of using
properties instead of public variables.
Events are a little different. An event is the way your control interacts with the rest of
the application. There are two different ways of creating events:
In order to expose a constituent event, the UserControl must raise the event. Start
by adding an event handler in the UserControl (for example, add a Click event to a
button control).
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:05 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
The “On” before the “Click” in the method is used because all controls have a method
that can be called to raise the event. In effect, the OnClick() method raises the Click
event from the UserControl.
In order to create a custom event, you can use delegates, which is the .NET standard
for using exposing and consuming events in Windows Forms. For example, to create the
event that should be triggered upon trying the student number too often in our
StudentValidate control, you could use this code:
And then you would raise the event by creating the “On” method:
You are not done yet. You must now allow the hosting application to use this event.
You need to add code within the Click event of your Validate button to check the
number of times the button has been clicked, and then cause the event to be raised:
Finally, the hosting application would use the control’s event to respond to the rais-
ing of the event:
If you are still unsure as to how this would work, refer back to Chapter 19 to review
the handling of events in Visual C# .NET.
Testing the Composite Control Remember that controls are not stand-alone
applications—they must be added to a hosting application first and then tested from
there. Follow these steps to test your control:
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:05 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
You should notice that these steps are very similar to the steps taken to test a control
that is created by extending an existing control. There is very little difference between the
two methods.
PART IV
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:05 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
EXAM TIP Use a composite control when you want to bring together the
functionality of many controls into one, reusable control.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:06 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
We have not examined the drawing capabilities of GDI+ (Graphics Device Interface)
yet—that will be covered in Chapter 24; however, the preceding code demonstrates the
way in which you would start to code your custom control.
The base class contains a default event handler, OnPaint, which really does nothing.
You must override it and insert the code that will make your control look the way you
want it to. Notice that the event handler is sent an argument of type System.Win-
dows.Forms.PaintEventArgs. Using that object, you can work with its most sig-
nificant property—an object of type System.Drawing.Graphics. The methods of
PART IV
the Graphics object allow you to work with the GDI+ code of the .NET Framework.
The draw methods, such as DrawString, allow you to paint a graphics object (in
this case a String) onto the drawing surface. Refer to Chapter 24 for more informa-
tion on GDI+.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:06 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:06 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
5. Click the Browse button in the Inheritance Picker warning dialog box, and find
the directory with the assembly that contains your base control.
PART IV
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:07 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
6. You will now see the Inheritance Picker, as shown in the following illustration.
You can either select the component from the list or click the Browse button to
point the directory system to the component you wish to use. For this example,
find and select the StudentValidate control created earlier in this chapter.
Click OK, and the control will be added to your project.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:07 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
Notice that the Property Explorer window allows you to see the properties of the
StudentValidate control. However, they are grayed out and are inaccessible to the
developer. This is because all properties are deemed to be private unless the control de-
signer chooses to expose them. In developing the StudentValidate control, you
could create public properties for those constituent properties that you want to let users
of the control work with.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:08 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
EXAM TIP A very important concept that we will introduce here is that you
have your own copy of the control when it is added to your project. This is
good news to developers who have, in the past, struggled with versioning of
controls. Version 1 might have belonged to a certain number of applications,
while version 2 belonged to different applications. By making the control part of the new
application, the version is implicitly bound to the application.
Here are the steps for adding a Toolbox bitmap to your control:
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:08 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
4. Once the icon file (MSN.ico) has been added to the project, you need to treat
it as an embedded resource. Click on the icon file in Solution Explorer, and
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:08 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:09 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
The MSN.ico string specifies the file (you can also add the path to the file in the
string) and the typeof parameter specifies that the icon is to be associated with the
StudentValidate type.
There are two other forms of this statement. Use whichever you need to access your
icon for the Toolbox bitmap:
EXAM TIP Remember that this line of code appears before the class
definition in your code module.
PART IV
Adding Attributes to Properties
By adding attributes to properties and events (or to the control itself), you can add de-
sign-time functionality to the control. The attributes become part of the metadata of the
control and allow you to specify how your custom properties will be grouped together
within the Properties Explorer, what types of default values exist for your properties, and
whether there are any custom editors for your custom properties.
Table 22-1 identifies the types of attributes that you can add to your control.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:09 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:09 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
Licensing a Control
Now that you have created a fabulous control that you will sell to millions of develop-
ers, you need to ensure that your control is being used in a controlled fashion. This in-
volves licensing your control and then checking whether the user is authorized to use
the control. Remember that a developer, who is your user, will be incorporating your
control into an application at design time. This is when you will want to issue a runtime
license so that users of the application will be able to use your control.
There are two modes of licensing:
PART IV
• Design-time licensing This allows a developer to use your control in their
new application.
• Runtime licensing This allows the user of the new application to run your
control.
When you add a licensed component to your application, the following things will
happen:
• The LicenseManager will look for a valid .LIC file. Remember that by
default it will look for the file in the same folder as the assembly.
• Upon finding a valid .LIC file, the LicenseManager creates and populates
the License object.
• The .LICX file is created automatically by Visual Studio .NET and is added to
the assembly.
• After the application has been built, the LC.exe utility gets to work. It does
the following things:
• Looks for the list of licensed controls in the .LICX file.
• Creates objects for all the controls found.
• Extracts the runtime license key.
• Creates the binary .Licenses file with the collection of runtime keys.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:09 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
EXAM TIP Add the xxxx.LIC file to the assembly folder in the
obj\Debug folder.
File Purpose
xxxx.LIC This is the design-time license file. It is a text file that should be in the
same directory as the assembly. The file must contain this statement:
“<namespace.classname> is a licensed component,” where you provide
the namespace and classname.
xxxx.LICX This is the design-time license file. This file consumes a licensed component.
It is a text file, and it lists all of the licensed components in an application.
This file is created automatically when you add a licensed component to an
application.
xxxx.Licenses This is a binary runtime license file. It is generated by the LC.exe utility.
Table 22-3 License Files
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
if (myLicense != null)
{
myLicense.Dispose();
myLicense = null;
}
Summary
In this chapter, we explored three ways of creating your own custom controls. We cre-
ated a control by inheriting from an existing control, by using a UserControl object to
host a number of existing controls, and by using a Control object to create our own
design. Depending on your position within the development team, you may or may not
have to ever create your own controls. Often a company has a team of “control develop-
ers” or uses controls developed by third parties.
The Microsoft exam will focus on your ability to derive a new control from a single
existing control, or to build a new control that is based on a combination of many exist-
ing controls. Spend some time creating your own controls until you are comfortable
PART IV
with the concepts presented in this chapter. In the next chapter, we will create the foun-
dations for deploying an application and look at the various techniques for packaging
and shipping an application.
Test Questions
1. Which file must be included in the assembly in order to provide a list of
licensed controls within the application?
A. xxxx.LIC
B. xxxx.LCX
C. xxxx.LICX
D. xxxx.Licenses
2. You are planning to create a new control that will be used in place of the
Button control. The new control will blink and change color whenever the
user moves the mouse over the control. Which control type would you use?
A. Derived control from the Button class.
B. Derived control from the Control class.
C. Derived control from the UserControl class.
D. Customized control using GDI+.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
i. Build the project.
ii. Add a new Web Forms project.
iii. Set the new project as the startup project.
iv. Run the project.
5. You are planning to create a control that will display two text boxes, ask the
user to enter a value in each box, and compare the contents for equality.
Which type of control would you build?
A. Derived control from the Button class.
B. Derived control from the Control class.
C. Derived control from the UserControl class.
D. Customized control using GDI+.
6. Which name is given to the controls that make up part of a composite control?
A. Extenders
B. Constituents
C. Hosts
D. Children
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
iii. Set the new project as the startup project.
iv. Run the project.
D. Version D
i. Build the project.
ii. Add a new Web Forms project.
iii. Set the new project as the startup project.
iv. Run the project.
13. Which object can you use from the PaintEventArgs object in order to draw
on your new control?
A. Graphics object.
B. Drawing object.
C. GDI+ object.
D. Control object.
14. What is wrong with the following code?
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyCustomControl: System.Windows.Forms.Control
// override the OnPaint event of the Control class
// draw your own user interface using GDI+
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
}
set
{
varValue = value;
}
}
}
C. public class NewLabel: System.Windows.Forms.Label
{
private System.ComponentModel.Container components = null;
private int varValue;
public NewLabel()
{
InitializeComponent();
}
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
22
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
22
PART IV
14. D.
15. B.
P:\010Comp\All-in-1\443-6\ch22.vp
Friday, August 23, 2002 5:05:10 PM