Windows Forms and Control Programming
Windows Forms and Control Programming
Programming
Prepared by:
Rajani Khushal K.
Introduction to Windows Forms
• System.Windows.Forms namespace used to
build windows based applications.
• There are three terms which belongs to
Windows.Forms namespace.
– Component
– Container
– Control
Introduction to Windows Forms
• Component:
– It is an object that permits sharing between
applications.
• Container:
– It is an object that can hold zero or more
components.
– A container is a grouping mechanism, and ensures
that sets of components are encapsulated and
manipulated in similar ways.
Introduction to Windows Forms
• Control:
– It is a component with a visual aspect.
– In Windows namespace, a control is a component
that presents a graphical interface on the window
desktop.
– Any visual interface we see on windows desktop is
a control, and any behind the control object of
that control is a component.
Introduction to Form
• The .NET framework provides all of the classes
that make up Windows Forms based
application through the System. Windows.
Forms namespace.
• Hierarchy of System. Windows. Forms
namespaces.
Introduction to Form
• Control
–ScrollableControl
• ContainerControl
–Form
–UserControl
Introduction to Form
• Control
– The Control Class is the fundamental base class for
other controls.
– It provides the basic functionality for a control,
such as sizing, visibility, and tab order.
• ScrollableControl
– It inherits directly from the Control class and
provides automatic scrolling capabilities for any
control that requires scroll bars.
Introduction to Form
• ContainerControl
– It inherits directly from the ScrollableControl class
and adds tabbing and focus management
functionality for controls that can host other
controls.
Introduction to Form
• Form:
– It inherits directly from the ContainerControl class
and represents any window displayed in the
application.
– The properties and methods provided by the Form
class allow us to display many different types of
forms, including dialog boxes and multiple
document interface (MDI) forms.
– All Windows forms are derived from this class.
Introduction to Form
• UserControl:
– It also inherits directly from the ContainerControl
class and provides an empty control that we can
use to create our own controls by using the
Windows Forms Designer.
Creating a
Windows Forms Application
Message Box
• It is a built in feature of Windows.
• A message box is a predefined window that
lets us display a message.
• We can also obtain simple responses from the
user such as Yes, No or Ok.
• In a window application, a message box is
supported by the MessageBox class.
• Messagebox is shown by using show() method
Message Box
• In windows application , a message box is
supported by the message box class.
• You can’t create a object of that class to
display a message box but you have to call the
static method called Show() which is defined
by message box
Message Box
• Messagebox is an enumeration that defines
the following values:
– OK
– AbortRetryIgnore
– OkCancel
– YesNo
– RetryCancel
– YesNoCancel
• It returns values by using DialogResult.
Message Box
• Returns value of Show method:
Border Style Get or Set type of border to display around the control
• It is defined
under System.Windows.Forms namespace.
Different Types of Controls
• Properties of Group Box
1. Location : Indicate location of group box
in windows form.
2. Size : Indicate the size of Group Box
3. Text : Indicate the text of group box ,
shows the purpose and content
inside the group box.
4. Name : Shows the name of group box
Different Types of Controls
• ListView Control
– It displays a list of items with icons.
– We can use a list view to create a user interface
like the right pane of Windows Explorer.
– The control has four view modes:
• LargeIcon
• SmallIcon
• List
• Details
Different Types of Controls
• ListView Control
Sorting Gets or Sets the how items in the list are sorted
Different Types of Controls
• ListView Control
Clear Remove all items and columns from list view control
BorderStyle Get or set the style of the border to display for the control