Unit - 5 (C#.NET Programming) User Controls, Reports & Setup
Unit - 5 (C#.NET Programming) User Controls, Reports & Setup
NET Unit : 5
Unit : 5th
User Controls, Crystal Reports & Project Setup
Page | 2
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Introduction
You can create your own controls if you don't find what you want from the list of predefined
controls available in .NET. You may need to create your own control because the controls that
are already available for you are very general and you might need a control which will have a
specific feature. These custom controls can then be placed in the toolbar together with other
controls.
There are two types of user defined controls, user controls and custom controls.
Custom controls are created from scratch; therefore, you need to define a lot of
functionalityand how the custom control will render.
User controls inherit from the UserControl class which is a derive class of the Control class that
other control uses. You won’t have access to the properties and methods of the components
that you will include in a user control because only properties and methods of the UserControl
class is exposed to you. But you can define properties and methods that will communicate to
the components of the user control.
Step 1:
Open Visual Studio and create a new project. From the list of templates, choose Windows
Forms Control Library and name it EditableLabel.
Page | 3
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Step 2:
You will have a blank canvas as displayed below:
It looks just like a Windows Forms but it has no frame. This is because you are designing a user
control. Any control you place inside it will be part of the user control.
Click the canvas and change its Name property toEditableLabel and its AutoSize property
to True.
Drag a label to the canvas and change its Text property toLabel and its Name property
to labelDisplay. Resize the canvas so that it fits the label inside it.
Adding Properties
Since we are creating a user control, then it will only contain properties and events that
the UserControlclass offers. It means there is no way for the user to access the properties of
the Label control we have added to the form. Although the UserControl class has a Text propety
which it inherits from Control, we need a more functionality involving the text inside our label.
To add a property to a user control, we simply need to add a property to the class of our user
control. While in Design View, press F7 to go to the Code Editor. Inside the EditableLabel class,
add the following property:
Note that we also used the override keyword because the Text property already exist in the User
Control.
Page | 4
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Page | 5
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
MyLable.Text = MyText.Text;
}
}
public override string Text
{
get
{
return MyLable.Text ;
}
set
{
MyLable.Text = value;
}
}
private void MyLable_DoubleClick(object sender, EventArgs e)
{
MyText.Text = MyLable.Text;
MyText.Show();
MyText.Focus();
MyLable.Hide();
}
Page | 6
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Crystal Reports
Crystal Reports is officially a member of the Visual Studio .NET product.
It is included in all major editions and ships in all languages available with Visual Studio
.NET. Crystal Reports .NET provides developers with the fastest, most productive way to
create and integrate presentation-quality, interactive reports that scale to meet the
demands of end users.
Crystal Reports .NET is a very powerful report writer. It offers a very well defined object
model that provides flexibility when integrating reports into Windows and Web
applications. It also comes with a highly customizable viewer component that gives
developers control on how their reports are presented to users.
ADO.NET Integration
ADO.NET is now the lingua-franca of data interchange in the .NET world. Crystal Reports .NET
provides the ability to use ADO.NET datasets as the data source for reports.
Page | 7
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
You can use the Crystal Report Designer to create a report from scratch, or you can use one of
the Crystal Report Experts to help you through the design process. The following Report Experts
are included in Crystal Reports for Visual Studio .NET:
1. Standard
2. Cross-Tab
3. Mail Label
Standard Report
Cross-Tab Report
The Cross-Tab Report Expert guides you through the creation of a report in which your data
is displayed as a cross-tab object. Three special tabs (Cross-Tab, Style, and Customize Style)
help you to create and format the cross-tab itself.
The Mail Label Report Expert lets you create a report that is formatted to print on a mailing
label of any size. You can use the Label tab to select a commercial label type, or you can
define your own layout of rows and columns for any style of multi-column report.
Page | 8
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Report Sections
Report Header – Appears at the top of the first page of the report.
Page Header – Appears after the Report Header on the first page. On all the remaining pages it appears
at the top of the page.
Details – The row that displays the record information. There is usually one detail row for every record
in the table.
Group Footer – Appears after all records of a group have been printed.
Report Footer – Appears as the bottom of the page for the last page in the report.
Formulas
Formulas in Crystal report have two forms of syntax; Basic and Crystal. In this paper, a few
of the details on the syntax, data types, return values and case sensitivity will be
demonstrated. Formulas are always used to return a value or Insert a value where desired.
When creating formulas, you have the option of using either Crystal or Basic syntax. Almost
any formula written with one syntax can be written with the other. Reports can contain
formulas that use Basic syntax as well as formulas that use Crystal syntax, but a single
formula can use only one syntax.
Page | 9
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Special Fields
There are various special fields which we can use for the
following purpose:
Print Date: Print Date Field is used to include the current date
when the report prints. This field can be placed in any section of
your report, depending on how often you want it to print. The
date can be changed in the Set Print Date and Time Dialog Box. I
have located print date field in the page header of the crystal
report in the above figure.
Record Selection Formula: Record Selection Formula Field is used to insert a selected record
into your report. (Use the Select Expert to create a record selection formula for your report.)
File Creation Date: File Creation Date Field is used to include a field that displays the date when
you created the report. I have located File creation field in the report footer of the crystal
report.
Record Number: Record Number Field is used to number each record printed in the Details
section of your report.
Page Number: Page Number Field is used to insert a field that prints the current page number.
These fields are most often placed in the Page Header or Page Footer sections. I have located
a Page Number field in the report footer of the crystal report.
Summary
Page | 10
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
1. Setup Project: Creates a Windows Installer project to which files can be added. This
project type is the most generic of the five.
2. Web Setup Project: Creates a Windows Installer web project to which files can be
added.
3. Merge Module Project: Creates a Windows Installer Merge Module project to which
files can be added. This project type is most commonly used for using third party
products.
4. Setup Wizard: Creates a Windows Installer project with the aid of a wizard.
5. Cab Project: Creates a Cab project to which files can be added.
File -> New -> Project -> Other Project Types -> Setup and Deployment -> Setup Project
Provide a name for the project as well choose the location where this project will be
established. Once you have done this click 'OK' and you should now see a screen like the
following.
Page | 11
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
2. User’s Desktop
Here you can set desktop short cut if
required.
The first thing we want to do here is to include the relevant files and folders we wish to install
on the user's machine.
This is accomplished by right clicking the Application Folder and selecting 'Add->Project
Output'. Click OK.
Page | 12
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
Create Shortcut
We could take additional steps such as manipulating the user's desktop with items such as a
shortcut; as well you can add a program group to the user's program group.
Name the shortcut as you want. I have given the name as Notepad. Drag and drop to User's
Desktop Folder
Page | 13
User Control, Crystal Report & Setup Programming With C#.NET Unit : 5
This Setup Project will now check the target machine for the .NET 2.0 Framework instead of the
.NET 3.5 Framework
Page | 14