08 gui 11

20
Slide 1 of 20 Session 11 Ver. 1.0 GUI Applications Development Using .NET Framework In this session, you will learn to: Work with user-defined components in the .NET applications Objectives

Upload: niit-care

Post on 17-Jul-2015

246 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 08 gui 11

Slide 1 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

In this session, you will learn to:Work with user-defined components in the .NET applications

Objectives

Page 2: 08 gui 11

Slide 2 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

To create a component in .NET, the user needs to identify the type of component and its properties and methods.

While creating a component, a user needs to:Use constructors

Add properties

Add methods

Creating a .NET Component

Page 3: 08 gui 11

Slide 3 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Using Constructors:.NET allows the passing of arguments to the object constructor by adding a constructor to the component's class module.

A component can have the following types of constructors:Public constructors

Internal constructors

Private constructors

Creating a .NET Component (Contd.)

Page 4: 08 gui 11

Slide 4 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Adding Properties:– Declaring a property allows you to control how a value is

changed or read.– You can declare a private variable that cannot be accessed

from outside a class.– You can create a property where you can have the Get and

Set accessors to read and set the value of a private variable.

Creating a .NET Component (Contd.)

Page 5: 08 gui 11

Slide 5 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Adding Methods:A method in a class can be:

a procedure that performs an operation on the data within the class.

a function that performs some operation on the data and returns the data from the class.

The method must be declared public to call a method from an instance of this class.

If a method is declared private, only methods within the same class can call that method.

Creating a .NET Component (Contd.)

Page 6: 08 gui 11

Slide 6 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Just a minute

Name the two main categories of .NET components.

Answer:1. In-process components

2. Out-of-process components

Page 7: 08 gui 11

Slide 7 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

There may be situations when you require a control, which performs actions that are not provided by any built-in control or need some enhanced feature.

The .NET Framework provides three types of user-defined controls. These are:

User control

Controls inherited from an existing control

Custom control

Creating User-Defined Controls in .NET Applications

Page 8: 08 gui 11

Slide 8 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

User Controls:– You combine two or more controls to create a new control.– User controls are also called as composite controls. – All user controls inherit the

System.Windows.Forms.UserControl class.

– The UserControl class can be used to combine the functionality of various controls into one unit, which can be reused.

– The UserControl class presents a single and unified interface.

– This interface contains members inherited from the control classes.

Creating User-Defined Controls in .NET Applications (Contd.)

Page 9: 08 gui 11

Slide 9 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Controls Inherited from an Existing Control:You can inherit from an existing control and then add additional features to it.

When you inherit a control from an existing control, the new control will have all the features of the inherited control.

Creating User-Defined Controls in .NET Applications (Contd.)

Page 10: 08 gui 11

Slide 10 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Just a minute

Name the method that has to be overridden to change the appearance of the control that is inherited from an existing control.

Answer:– The OnPaint() method

Page 11: 08 gui 11

Slide 11 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Custom Controls:– Custom controls have the highest degree of customizability.– Users can build a control that has very little resemblance with

the built-in controls in terms of both appearance and functionality.

– All custom controls inherit from the System.Windows.Forms.Control class.

Creating User-Defined Controls in .NET Applications (Contd.)

Page 12: 08 gui 11

Slide 12 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Just a minute

Name the class to be inherited for creating a custom control.

Answer:System.Windows.Forms.Control

Page 13: 08 gui 11

Slide 13 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Demo: Implementing a .NET Component

Problem Statement:Build a nonvisual .NET component called TimeComponent. It should get the current date and time from the host computer. In addition, create an application that will use this component and display the time returned.

Page 14: 08 gui 11

Slide 14 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Demo: Implementing a .NET Component (Contd.)

Solution:To use a component, you need to perform the following tasks:

1. Create a .NET component.

2. Create a user application.

Page 15: 08 gui 11

Slide 15 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Demo: Creating a User Control

Problem Statement:Build a user control called DigitalClock. This should contain a label control that displays time. In addition, create an application that will use this control.

Page 16: 08 gui 11

Slide 16 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Solution:To build a user control and an application, you need to perform the following tasks:

1. Create a user control.

2. Create a user application.

Demo: Creating a User Control (Contd.)

Page 17: 08 gui 11

Slide 17 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Demo: Creating Inherited Controls

Problem Statement:Build a NumericTextBox control that contains a TextBox control. The latter should accept only a numeric value as input. In addition, create an application that will use this control.

Page 18: 08 gui 11

Slide 18 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

Solution:To create the NumericTextBox control and an application, which will implement the NumericTextBox control, you need to perform the following tasks:

1. Create an inherited control.

2. Create a user application.

Demo: Creating Inherited Controls (Contd.)

Page 19: 08 gui 11

Slide 19 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

In this session, you learned that:To create a component in .NET, the user needs to identify the type of component and its properties and methods.

While creating a component, a user needs to:• Use constructors• Add properties• Add methods

In .NET programming environment, you can have the following types of constructors:

Public constructor

Internal constructor

Private constructor

Summary

Page 20: 08 gui 11

Slide 20 of 20Session 11Ver. 1.0

GUI Applications Development Using .NET Framework

The .NET Framework provides three types of user-defined controls. These are:

User controls

Controls inherited from an existing control

Custom controls

Summary (Contd.)