More Related Content
Similar to Vb.net session 10
Similar to Vb.net session 10 (20)
Vb.net session 10
- 1. Introducing User Controls And Managing
Components
Pre-Assessment Questions
• Consider the following statements:
• Statement A: Timer is an in-built component.
• Statement B: ServiceController is an in-built components.
Which of the following is correct with respect to the above statements?
d. Both, Statement A and Statement B, are False.
e. Both, Statement A and Statement B, are True.
f. Statement A is True and Statement B is False.
g. Statement A is False and Statement B is True.
©NIIT Creating and Managing components Lesson 1B / Slide 1 of 27
- 2. Introducing User Controls And Managing
Components
Pre-Assessment Questions (Contd.)
• Consider the following statements:
• Statement A. The wrapper that allows interaction between COM and
.NET is called RCW.
• Statement B. Implementation of component is called ActiveX.
Which of the following is correct with respect to the above statements?
d. Both, Statement A and Statement B, are False.
e. Both, Statement A and Statement B, are True.
f. Statement A is True and Statement B is False.
g. Statement A is False and Statement B is True
©NIIT Creating and Managing components Lesson 1B / Slide 2 of 27
- 3. Introducing User Controls And Managing
Components
Pre-Assessment Questions (Contd.)
1. The assemblies that are required during the execution of an assembly are
called:
• Metadata
• Portable executable
• Manifest
• Dependencies
3. Using COM+, the business logic can be placed in:
• First tier
• Middle tier
• Third tier
• Any tier
©NIIT Creating and Managing components Lesson 1B / Slide 3 of 27
- 4. Introducing User Controls And Managing
Components
Pre-Assessment Questions (Contd.)
• Consider the following statements:
• Statement A. Friend constructor can be used if you want to use a
component inside an assembly but not outside it.
• Statement B. Private constructor can be used in a component if you
want to use it outside the component class.
Which of the following is correct with respect to the above statements?
d. Both, Statement A and Statement B, are False.
e. Both, Statement A and Statement B, are True.
f. Statement A is True and Statement B is False.
g. Statement A is False and Statement B is True.
©NIIT Creating and Managing components Lesson 1B / Slide 4 of 27
- 5. Introducing User Controls And Managing
Components
Solutions to Pre-Assessment
Questions
1. b.
2. b.
3. d. Dependencies
4. d. Any tier
5. c.
©NIIT Creating and Managing components Lesson 1B / Slide 5 of 27
- 6. Introducing User Controls And Managing
Components
Objectives
In this lesson, you will learn to:
• Create customized user controls
• Add existing components and controls to a user control
• Declare and raise events in a user control
• Create a user control
• Identify the need for Web services
• Identify the enabling technologies in Web services
• Add and remove Web references
©NIIT Creating and Managing components Lesson 1B / Slide 6 of 27
- 7. Introducing User Controls And Managing
Components
Understanding User Controls
• In Visual Basic .NET, you use controls such as list boxes, text boxes, menus,
check boxes, and buttons to add user interaction capability to the graphical
applications.
• These controls are visual components that can be used across applications.
©NIIT Creating and Managing components Lesson 1B / Slide 7 of 27
- 8. Introducing User Controls And Managing
Components
User Controls
• You can create composite reusable controls and selectively expose the
properties of these controls.
• The UserControl class can be used to combine the functionality of different
controls into one unit that can be reused.
• The UserControl class can contain multiple child controls.
• The UserControl class presents a single and unified interface.
©NIIT Creating and Managing components Lesson 1B / Slide 8 of 27
- 9. Introducing User Controls And Managing
Components
Customized User Controls
• While creating a user control the class inherits from the UserControl class by
default.
• To inherit the user control from another existing control, the Inherits
System.Windows.Forms. UserControl statement needs to be changed to the
class from which you want to inherit the control.
©NIIT Creating and Managing components Lesson 1B / Slide 9 of 27
- 10. Introducing User Controls And Managing
Components
Adding Properties And Functions
• To add functionalities to a control, code has to be added for the property by
viewing the code for the control.
• The code will consist of the get and set methods of the property.
©NIIT Creating and Managing components Lesson 1B / Slide 10 of 27
- 11. Introducing User Controls And Managing
Components
Testing a Control
• A control is always used in a container.
• To test a control, you must host it in a Windows Form.
©NIIT Creating and Managing components Lesson 1B / Slide 11 of 27
- 12. Introducing User Controls And Managing
Components
Creating Custom Controls from the
Control Class
• To build a control from scratch, you can inherit from the Control class.
• The Control class defines input from the mouse and the keyboard.
• The Control class also defines the bounds and size of controls.
©NIIT Creating and Managing components Lesson 1B / Slide 12 of 27
- 13. Introducing User Controls And Managing
Components
Inheriting from a User Control
• User control can be used to build other controls.
• Parent methods of the base class can be overridden to provide extended
functionality in the inherited control.
©NIIT Creating and Managing components Lesson 1B / Slide 13 of 27
- 14. Introducing User Controls And Managing
Components
Rendering Graphical Interface of
Custom Controls
• To provide a graphical interface to your custom controls you need to override
the OnPaint() method of the control class.
• The OnPaint() method is executed when a control is first drawn and when a
control is resized.
©NIIT Creating and Managing components Lesson 1B / Slide 14 of 27
- 15. Introducing User Controls And Managing
Components
Raising Events
• To use event handling, you should be able to:
• Declare events.
• Raise events.
• handle the events raised by your control.
©NIIT Creating and Managing components Lesson 1B / Slide 15 of 27
- 16. Introducing User Controls And Managing
Components
Declaring Events
• You can declare events within:
• Classes.
• Structures.
• Interfaces.
• To declare an event, you need to use the Event keyword.
• In Visual Basic .NET, you need to use the RaiseEvent keyword to raise an
event.
• Any object capable of raising an event is an event sender.
• Event handlers are special types of procedures that are called when an event
occurs.
©NIIT Creating and Managing components Lesson 1B / Slide 16 of 27
- 17. Introducing User Controls And Managing
Components
Delegates
• In Visual Basic .NET, you use delegates to call event procedures.
• Delegates are objects that you use to call the methods of other objects.
• Delegates in Visual Basic .NET can reference both shared and instance
methods.
©NIIT Creating and Managing components Lesson 1B / Slide 17 of 27
- 18. Introducing User Controls And Managing
Components
Delegates and AddressOf Operator
• The AddressOf operator implicitly creates an instance of a delegate.
• Event handlers can be removed dynamically by using the RemoveHandler
keyword.
©NIIT Creating and Managing components Lesson 1B / Slide 18 of 27
- 19. Introducing User Controls And Managing
Components
Demo
Creating a User Control
©NIIT Creating and Managing components Lesson 1B / Slide 19 of 27
- 20. Introducing User Controls And Managing
Components
Problem Statement
• Build a user Control named ‘MyClock’ that will display the current time and
will also perform the function of an alarm. Test this user control in a VB.NET
application.
©NIIT Creating and Managing components Lesson 1B / Slide 20 of 27
- 21. Introducing User Controls And Managing
Components
Solution
• To build and use the ‘MyClock’ user control in an application, you need to
perform the following steps:
1. Create the User Control.
2. Add Windows Controls to the User Controls.
3. Create the Inherited Control.
4. Add Properties to the User Control.
5. Test the User Control.
©NIIT Creating and Managing components Lesson 1B / Slide 21 of 27
- 22. Introducing User Controls And Managing
Components
Understanding Web Services
• The evolution of the Internet has resulted in a gradual shift from desktop to
distributed applications.
• The development of distributed applications involves ensuring that components
hosted in heterogeneous environments are interoperable.
• To address these issues, Web Services have been introduced.
©NIIT Creating and Managing components Lesson 1B / Slide 22 of 27
- 23. Introducing User Controls And Managing
Components
Introduction to Web Services
• A Web service exposes a number of methods that provide functionality that
can be used by one or more applications, regardless of the programming
languages, operating systems, and hardware platforms used to develop them.
• The methods that provide such functionality are called Web methods.
• An application that uses a Web service is called a Web service client.
©NIIT Creating and Managing components Lesson 1B / Slide 23 of 27
- 24. Introducing User Controls And Managing
Components
Enabling Technologies used in Web
Services
• Enabling technologies used in Web Services are:
• XML
• XML is a plain-text format that can be understood by any platform.
• SOAP
• SOAP is a standard communication protocol for interchanging
information in a structured format in a distributed environment.
• WSDL
• WSDL is a markup language that describes a Web service.
• UDDI
• UDDI provides a standard mechanism to register and discover a Web
service.
©NIIT Creating and Managing components Lesson 1B / Slide 24 of 27
- 25. Introducing User Controls And Managing
Components
Adding and Removing Web references
from a Project
• A Web Reference can be added and removed by using Solution Explorer.
• A Web Service can be called programmatically.
©NIIT Creating and Managing components Lesson 1B / Slide 25 of 27
- 26. Introducing User Controls And Managing
Components
Summary
In this lesson, you learned that:
• User controls are visual components.
• You can create a reusable unit of controls and selectively expose their
properties by inheriting from the UserControl class.
• You can create a customized user control by inheriting from an existing
control.
• You can override the OnPaint() method to customize the drawing of a
control.
• You can declare, raise, and handle events.
• Delegates are objects that you use to call the methods of other objects.
©NIIT Creating and Managing components Lesson 1B / Slide 26 of 27
- 27. Introducing User Controls And Managing
Components
Summary (Contd.)
• A Web service exposes functionality that can be used by one or more
applications, regardless of the programming languages, operating systems,
and hardware platforms used to develop them.
• The functionality exposed by a Web service can be accessed by applications
by using Internet standards, such as HyperText Transfer Protocol (HTTP) and
eXtensible Markup Language (XML).
• To be able to communicate with each other, a Web service and a client
application must agree upon a common protocol. SOAP is a standard
communications protocol for interchanging information in a structured format
in a distributed environment.
• To be able to use a Web service, the developers of a client application need
to know the methods exposed by the Web service and the parameters to be
passed to these methods. Web Services Description Language (WSDL) is a
markup language, which is used to describe a Web service.
• The Universal Description Discovery and Integration (UDDI) initiative is used
to allow client applications to discover the Web services provided by various
Web service providers.
©NIIT Creating and Managing components Lesson 1B / Slide 27 of 27