Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
08 gui 11
1. GUI Applications Development Using .NET Framework
Objectives
In this session, you will learn to:
Work with user-defined components in the .NET applications
Ver. 1.0 Session 11 Slide 1 of 20
2. GUI Applications Development Using .NET Framework
Creating a .NET Component
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
Ver. 1.0 Session 11 Slide 2 of 20
3. GUI Applications Development Using .NET Framework
Creating a .NET Component (Contd.)
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
Ver. 1.0 Session 11 Slide 3 of 20
4. GUI Applications Development Using .NET Framework
Creating a .NET Component (Contd.)
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.
Ver. 1.0 Session 11 Slide 4 of 20
5. GUI Applications Development Using .NET Framework
Creating a .NET Component (Contd.)
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.
Ver. 1.0 Session 11 Slide 5 of 20
6. 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
Ver. 1.0 Session 11 Slide 6 of 20
7. GUI Applications Development Using .NET Framework
Creating User-Defined Controls in .NET Applications
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
Ver. 1.0 Session 11 Slide 7 of 20
8. GUI Applications Development Using .NET Framework
Creating User-Defined Controls in .NET Applications (Contd.)
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.
Ver. 1.0 Session 11 Slide 8 of 20
9. GUI Applications Development Using .NET Framework
Creating User-Defined Controls in .NET Applications (Contd.)
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.
Ver. 1.0 Session 11 Slide 9 of 20
10. 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
Ver. 1.0 Session 11 Slide 10 of 20
11. GUI Applications Development Using .NET Framework
Creating User-Defined Controls in .NET Applications (Contd.)
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.
Ver. 1.0 Session 11 Slide 11 of 20
12. 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
Ver. 1.0 Session 11 Slide 12 of 20
13. 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.
Ver. 1.0 Session 11 Slide 13 of 20
14. 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.
Ver. 1.0 Session 11 Slide 14 of 20
15. 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.
Ver. 1.0 Session 11 Slide 15 of 20
16. GUI Applications Development Using .NET Framework
Demo: Creating a User Control (Contd.)
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.
Ver. 1.0 Session 11 Slide 16 of 20
17. 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.
Ver. 1.0 Session 11 Slide 17 of 20
18. GUI Applications Development Using .NET Framework
Demo: Creating Inherited Controls (Contd.)
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.
Ver. 1.0 Session 11 Slide 18 of 20
19. GUI Applications Development Using .NET Framework
Summary
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
Ver. 1.0 Session 11 Slide 19 of 20
20. GUI Applications Development Using .NET Framework
Summary (Contd.)
The .NET Framework provides three types of user-defined
controls. These are:
User controls
Controls inherited from an existing control
Custom controls
Ver. 1.0 Session 11 Slide 20 of 20
Editor's Notes
Start the session by sharing the session objectives with the students.
Using this slide, the faculty must discuss with the students that they can create components in .NET. These components may comprise of constructors to initialize data members. In addition, it can include set and get methods to initialize properties and methods to perform some specific tasks.
Using this slide, the faculty must discuss with the students the three types of constructor that a .NET component can have.
Using this slide, the faculty must discuss with the students the way of adding properties to a .NET component. The faculty should discuss the purpose of Set and Get methods in modifying the value of properties.
Using this slide, the faculty must discuss that methods can be created within components. These methods are normal functions to perform a particular task that may or may not return a value. The faculty should also discuss the access specifiers that can be used with the methods and the effect of using these access specifiers.
Reiterate the concepts taught earlier by asking the given question.
Use this slide to discuss that it is possible to create three different types of controls in .NET. These have been listed in the slide. The faculty can give an example to make the students understand these in a better way. User Control: You combine two or more controls to create a new control. The new control will act like a single control. User controls are also called as composite controls . For example, a control is created using a form and a text box to connect to a database. Inheriting form an existing control: You may require some additional function to be added to an existing control. You can inherit from an existing control and then add the required features to it. The faculty can use the same example of a numeric text box. Custom Control: Custom controls have the highest degree of customizability. You may require a control that has very little resemblance with the built-in controls in terms of both appearance and functionality. The faculty can explain the example from the SG - if you need an analog clock control, combining controls or inheriting a control will be of very little help. You will have to create the control from scratch. The following four slides discuss these in detail.
Use this slide to discuss the steps for creating user control. It will be a good teaching practice to demonstrate this with the help of a small example.
Reiterate the concepts taught earlier by asking the given question.
Reiterate the concepts taught earlier by asking the given question.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
You can summarize the session by using the summary given in the slides. In addition, you can also ask students summarize what they have learnt in this session.
You can summarize the session by using the summary given in the slides. In addition, you can also ask students summarize what they have learnt in this session.