[go: up one dir, main page]

0% found this document useful (0 votes)
10 views34 pages

Unit 2

Uploaded by

prajapatibhavy10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views34 pages

Unit 2

Uploaded by

prajapatibhavy10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

1

Unit – 2 (.Net Framework)

What is C#:
C# is a modern, general-purpose, object-oriented programming language
developed by Microsoft and approved by European Computer Manufacturers
Association (ECMA) and International Standards Organization (ISO).
C# was developed by Anders Hejlsberg and his team during the development of
.Net Framework. C# is designed for Common Language Infrastructure (CLI),
which consists of the executable code and runtime environment that allows use
of various high-level languages on different computer platforms and
architectures.
C# code is compiled as managed code. Combines the best features of Visual
Basic, C++ and Java
“C#, pronounced "C-sharp," is an object-oriented programming language from
Microsoft that enables developers to build applications that run on the .NET
platform. C# has its roots in the C family of programming languages and shares
many of the same characteristics as those found in C and C++, as well as in Java
and JavaScript”.

The following reasons make C# a widely used professional language:


➢ It is a modern, general-purpose programming language
➢ It is object oriented.
➢ It is component oriented.
➢ It is easy to learn.
➢ It is a structured language.
➢ It produces efficient programs.
➢ It can be compiled on a variety of computer platforms.
➢ It is a part of .Net Framework

Creat By : kuldeep padhya


2
Unit – 2 (.Net Framework)

C# History:
.Net Framework is a software development platform developed by Microsoft
for building and running Windows applications. The .Net framework consists of
developer tools, programming languages, and libraries to build desktop and web
applications. It is also used to build websites, web services, and games.
The .Net framework was meant to create applications, which would run on
the Windows Platform. The first version of the .Net framework was released in
the year 2002.
The Microsoft .Net framework can be used to create both – Form-based
and Web-based applications. Web services can also be developed using the .Net
framework.
The framework also supports various programming languages such as Visual
Basic, C# , C++, and F#. So developers can choose and select the language to
develop the required application. C# and visual basic are the main
languages used in .Net framework.
Version .NET Framework Visual Studio
C# 1.0 .NET Framework Visual Studio .NET
1.0/1.1 2002
C# 2.0 NET Framework 2.0 Visual Studio 2005
C# 3.0 NET Framework 3.0/3.5 Visual Studio 2008
C# 4.0 NET Framework 4.0 Visual Studio 2010
C# 5.0 NET Framework 4.5 Visual Studio 20012/13
C# 6.0 NET Framework 4.6 Visual Studio 2013/15

Creat By : kuldeep padhya


3
Unit – 2 (.Net Framework)

Feature of C#:
1. Simple
2. Modern Programming Language
3. Object Oriented
4. Type Safe
5. Interoperability
6. Scalable and Updateable
7. Component Oriented
8. Structured Programming Language
9. Rich Library
10. Fast Update

Creat By : kuldeep padhya


4
Unit – 2 (.Net Framework)

1) Simple:
C# is a simple language in the sense that it provides structured approach (to
break the problem into parts), rich set of library functions, data types etc.
2) Modern Programming Language:
C# programming is based upon the current trend and it is very powerful and
simple for building scalable, interoperable and robust applications,
3) Object Oriented:
C# is object oriented programming language. OOPs makes development and
maintenance easier where as in Procedure-oriented programming language it is
not easy to manage if code grows as project size grow.
4) Type Safe:
C# type safe code can only access the memory location that it has permission to
execute, Therefore it improves a security of the program
5) Interoperability:
Interoperability process enables the C# programs to do almost anything that a
native C++ application can do.
6) Scalable and Updateable:
C# is automatic scalable and updateable programming language. For updating
our application we delete the old files and update them with new ones.
7) Component Oriented:
C# is component oriented programming language. It is the predominant
software development methodology used to develop more robust and highly
scalable applications.
8) Structured Programming Language:
C# is a structured programming language in the sense that we can break the
program into parts using functions. So, itis easy to understand and modify.
9) Rich Library:
C# provides a lot of inbuilt functions that makes the development fast.

Creat By : kuldeep padhya


5
Unit – 2 (.Net Framework)

10) Fast Speed:


The compilation and execution time of C# language is fast.
Class and Object:
What is Class:
“In simple word class is a collection of variable and method”. A class is a user-
defined layout or blueprint of an object that describes what a specific kind of
object will lookalike. A class description consists of two things: 1) Attributes or
member variables, and 2) Implementations of behavior or member functions. So
in object-oriented terminology: A class is a blueprint that defines the variables
and the methods common to all objects of a certain kind. It helps us to bind data
and methods together, making the code reusable, unlike procedural language.
For example, a mobile phone has attributes like a brand name, RAM, and
functions like texting and calling. Thus, the mobile phone is a class of various
phones (the objects).
Declaration of Class:
Generally, a class declaration contains only keyword class, followed by an
identifier(name)of the class. But there are some optional attributes which can be
used with class declaration according to the application requirement. In general,
class declarations can include these components
Modifiers: A class can be public or internal etc. By default modifier of class is
internal.
Keyword class: A class keyword is used to declare the type class.
Class Identifier: The variable of type class is provided. The identifier(or name
of class) should begin with a initial letter which should be capitalized by
convention.
Base class or Super class: The name of the class’s parent (superclass), if any,
preceded by the : (colon). This is optional.
Interfaces: A comma-separated list of interfaces implemented by the class, if
any, preceded by the : (colon). A class can implement more than one interface.
This is optional.

Creat By : kuldeep padhya


6
Unit – 2 (.Net Framework)

Body: The class body is surrounded by { } (curly braces). Constructors in class


are used for initializing new objects. Fields are variables that provide the state of
the class and its objects, and methods are used to implement the behavior of the
class and its objects
Syntax:
Modifier Class Classname
{
Collection of Variable
Collection of Method
}
Example:
Public/Private Class Xyz
{
Int a=10;
Int b=20;
Public void sum()
{
Int c = a+b;
}
}

Creat By : kuldeep padhya


7
Unit – 2 (.Net Framework)

Object:-
When a class is defined, only the specification for the object is defined; no
memory or storage is allocated. To use the data and access functions defined
in the class, you need to create objects.
In other words, object is an entity that has state and behavior. Here, state
means data and behavior means functionality. “Object is a basic runtime
entity, it is created at runtime”. Object is an instance of a class. All the
members of the class can be accessed through object.
Accessing data members and member functions:
The data members and member functions of class can be accessed using the
dot(‘.’) operator with the object. For example if the name of object is obj and
you want to access the member function with the name printName() then you
will have to write obj.printName() .
Syntax:
Classname objectname = new object();
Note:- Here new keyword is used for allocation of memory to data member.
Public class addition
{
Public int add(int a, int b)
{
int c = a + b;
return c;
}
}
Now access a class property
{
addition a = new addition()
a.add(10,20)
}

Creat By : kuldeep padhya


8
Unit – 2 (.Net Framework)

C# Variable and datatype:


What is Variable:
A variable is a name given to a storage area that is used to store values of various
data types. Each variable in C# needs to have a specific type, which determines
the size and layout of the variable's memory.
For example, a variable can be of the type String, which means that it will be used
to store a string value. Based on the data type, specific operations can be carried
out on the variable
Since there are numerous different languages, .NET has specified those
commonalities in something called the Common Language Specification (CLS).
CLS defines a set of features that are needed by many common applications.
The basic value types provided in C# can be categorized as
1) Integer type: sbyte, byte, short, ushort, int, uint, long, ulong, and char
2) Float : float and double
3) Decimal types: Decimal
4) Boolean types true or false values, as assigned
5) Nullable types Nullable data types
6) String types string
Defining variables:
Here, data_type must be a valid C# data type including char, int, float, double,
or any user-defined data type, and variable_list may consist of one or more
identifier names separated by commas.
Syntax for variable definition in C#:
<data_type> <variable_list>;
Initializing Variables:
Variables are initialized (assigned a value) with an equal sign followed by a
constant expression. The general form of initialization is
variable_name = value;

Creat By : kuldeep padhya


9
Unit – 2 (.Net Framework)
Some examples are
int d = 3, f = 5; /* initializing d and f. */
byte z = 22; /* initializes z. */
double pi = 3.14159; /* declares an approximation of pi. */
char x = 'x’; /* the variable x has the value 'x'. */.

Property Method And Event:


What is Property:
Property in C# is a class member that exposes the class private fields. Internally,
C# properties are special methods called accessors. A C# property has two
accessors, a get property accessor or a getter and a set property accessor or a
setter. A get accessor returns a property value, and a set accessor assigns a new
value. The value keyword represents the value of a property.
Properties in C# and .NET have various access levels defined by an access
modifier. Properties can be read-write properties, read-only properties, or write-
only properties. The read-write property implements both a get and a set accessor.
A write-only property implements a set accessor but no get accessor. A read-only
property implements a get accessor but no set accessor.
Usually, inside a class, we declare a data field as private and will provide a set of
public SET and GET methods to access the data fields. This is a good
programming practice since the data fields are not directly accessible outside the
class. We must use the set/get methods to access the data fields.

Creat By : kuldeep padhya


10
Unit – 2 (.Net Framework)

What is Method:
Method: “A method is a block of code which only runs when it is called”. You
can pass data, known as parameters, into a method. Method are used to
perform certain actions, and they are also known as functions. Why use
methods? To reuse code: define the code once, and use it many times.
Create a Method:
A method is defined with the name of the method, followed by parentheses ().
C# provides some pre-defined methods, which you already are familiar with,
such as Main(), but you can also create your own methods to perform certain
actions
Syntax:
AccessModifier returnType Method Name()
{
Body
}

returnType :- It specifies what type of value a method returns. For example, if


a method has an int return type then it returns an int value. If the method does
not return a value, its return type is void.
methodName :- It is an identifier that is used to refer to the particular method
in a program.
method body :- It includes the programming statements that are used to
perform some tasks. The method body is enclosed inside the curly braces { }
Parameter :- we can also create a method that accepts some value. These
values are called method parameters
Public int addnumber(int a, int b)

Creat By : kuldeep padhya


11
Unit – 2 (.Net Framework)

Call a Method
To call (execute) a method, write the method's name followed by two
parentheses () and a semicolon;

Example:
Class Program{
Int addnumber(int a, int b) //Method Declare//
{
Int sum = a+b;
Return sum;
}
Static void main(string[] args ) {
Program p1 = new program();
Int sum = p1.addnumber(100,100) //Method call//
Console.WriteLine(“sum=” +sum);
Console.ReadLine();
}
}
}

Creat By : kuldeep padhya


12
Unit – 2 (.Net Framework)

Event:- Events are user actions such as key press, clicks, mouse movements, etc.,
or some occurrence such as system generated notifications. Applications need to
respond to events when they occur. For example, interrupts. Events are used for
inter-process communication
Using Delegates with Events:
The events are declared and raised in a class and associated with the event
handlers using delegates within the same class or some other class. The class
containing the event is used to publish the event. This is called the publisher class.
Some other class that accepts this event is called the subscriber class. Events use
the publisher-subscriber model.
A publisher is an object that contains the definition of the event and the delegate.
The event-delegate association is also defined in this object. A publisher class
object invokes the event and it is notified to other objects.
A subscriber is an object that accepts the event and provides an event handler.
The delegate in the publisher class invokes the method (event handler) of the
subscriber class.
What is Array:
An array stores a fixed-size sequential collection of elements of the same type.
An array is used to store a collection of data, but it is often more useful to think
of an array as a collection of variables of the same type stored at contiguous
memory locations.
Instead of declaring individual variables, such as number0, number1, ..., and
number99, you declare one array variable such as numbers and use numbers[0],
numbers[1], and ..., numbers[99] to represent individual variables. A specific
element in an array is accessed by an index. All arrays consist of contiguous
memory locations. The lowest address corresponds to the first element and the
highest address to the last element.
Declaring Arrays
To declare an array in C#, you can use the following syntax −
datatype[] arrayName;

Creat By : kuldeep padhya


13
Unit – 2 (.Net Framework)

Initializing an Array
Declaring an array does not initialize the array in the memory. When the array
variable is initialized, you can assign values to the array. Array is a reference
type, so you need to use the new keyword to create an instance of the array. For
example
double[] balance = new double[10];
Assigning Values to an Array
❖ You can assign values to individual array elements, by using the index
number, like −
double[] balance = new double[10];
balance[0] = 4500.0;
❖ You can assign values to the array at the time of declaration, as shown −
double[] balance = { 2340.0, 4523.69, 3421.0};
You can also create and initialize an array, as shown −
int [] marks = new int[5] { 99, 98, 92, 97, 95};
❖ You may also omit the size of the array, as shown −
int [] marks = new int[] { 99, 98, 92, 97, 95};
❖ You can copy an array variable into another target array variable. In such case,
both the target and source point to the same memory location −
int [] marks = new int[] { 99, 98, 92, 97, 95};
int[] score = marks;

Creat By : kuldeep padhya


14
Unit – 2 (.Net Framework)

C# Inheritance:
Inheritance: - it is a process in which one object acquires all the properties and
behaviours of its parent object automatically. In such way, you can reuse, extend
or modify the attributes and behaviours which are defined in other class.
The class which inherits the members of another class is called derived class and
the class whose members are inherited is called base class. The derived class is
the specialized class for the base class.
One of the most important concepts in object-oriented programming is
inheritance. Inheritance allows us to define a class in terms of another class,
which makes it easier to create and maintain an application. This also provides
an opportunity to reuse the code functionality and speeds up implementation time.
When creating a class, instead of writing completely new data members and
member functions, the programmer can designate that the new class should
inherit the members of an existing class. This existing class is called the baseclass,
and the new class is referred to as the derived class.
Inheritance (Derived and Base Class)
In C#, it is possible to inherit fields and methods from one class to another. We
group the "inheritance concept" into two categories:
Derived Class (child) - the class that inherits from another class
Base Class (parent) - the class being inherited from
Syntax:
class derived-class:base-class
{
// methods and fields
}
To inherit from a class, use the : symbol.

Creat By : kuldeep padhya


15
Unit – 2 (.Net Framework)

Types of inheritance:
1. Single Inheritance
In single inheritance, a single derived class inherits from a single base class.

2. Multilevel Inheritance
In multilevel inheritance, a derived class inherits from a base and then the
same derived class acts as a base class for another class.

3. Hierarchical Inheritance
In hierarchical inheritance, multiple derived classes inherit from a single base
class.2. Multilevel Inheritance

Creat By : kuldeep padhya


16
Unit – 2 (.Net Framework)

4. Multiple Inheritance
In multiple inheritance, a single derived class inherits from multiple base
classes. C# doesn't support multiple inheritance. However, we can achieve
multiple inheritance through interfaces.

5. Hybrid Inheritance
Hybrid inheritance is a combination of two or more types of inheritance. The
combination of multilevel and hierarchical inheritance is an example of
Hybrid inheritance.

Creat By : kuldeep padhya


17
Unit – 2 (.Net Framework)

What is Windows Form:


Windows Forms is a Graphical User Interface (GUI) class library which is
bundled in .Net Framework. Its main purpose is to provide an easier interface to
develop the applications for desktop, tablet, PCs. It is also termed as the
WinForms. The applications which are developed by using Windows Forms or
WinForms are known as the Windows Forms Applications that runs on the
desktop computer. WinForms can be used only to develop the Windows Forms
Applications not web applications. WinForms applications can contain the
different type of controls like labels, list boxes, tooltip etc.
There are two form
1) SDI :- Single Document Interface
2) MDI :- Multiple Document Interface
1) SDI (Single Document Interface) :-
This is a term which is known as Single Document Interface and is a Graphic
User Interface which is able to show one document at a time on the screen. Any
type of program which does not have the ability to show more than one document
is considered to be and SDI type of user interface.
An SDI opens each document in its own primary window. Each window has its
own menu, toolbar, and entry in the task bar. Therefore, an SDI is not constrained
to a parent window. This makes it easier
for the user to view the contents of the various windows. Notepad is an example
of an SDI application
The main advantage of this type of interface is that it is simple to use and a
complicated task can be performed in an easy manner without switching from one
app to the other

Creat By : kuldeep padhya


18
Unit – 2 (.Net Framework)

2) MDI (Multiple Document Interface):- This term is known as Multiple


Document Interface and is the type of Graphic User Interface which is able to
show more than a single document at a time on the screen. Any type of program
which has the ability to show more than one document is considered to be and
MDI type of user interface. The best examples of this type of interface include all
the latest web browsers where multiple tabs can be opened at the same time to
see all the information that is required. The main advantage of such type of
interface is that the work can be performed quickly as compared to one screen but
the main disadvantage is that the latest opened windows are not shown once they
are closed.
The MDI has a parent window, and any number of child windows. The child
windows usually share various parts of the parent window’s interface, including
the menu bar, toolbar and status bar. Therefore, an MDI is constrained to the
parent window. Microsoft Visual Studio is an MDI application. It is also available
as a GUI tool (MDI Form) in software developing API such as Microsoft Visual
Studio

Creat By : kuldeep padhya


19
Unit – 2 (.Net Framework)

Difference Between MDI Vs SDI:


MDI SDI
Full Name Multiple Document Interface Single Document
Interface
Type It is the type of Graphic User It is a Graphic User
Interface which is able to show more Interface which is able to
than a single document at a time on show one document at a
the screen. time on the screen
Maximization All the documents can be maximized There needs to be a
in the MDI special command in order
to maximize the
documents
Example Latest web browsers. windows notepad

Creat By : kuldeep padhya


20
Unit – 2 (.Net Framework)

Common Controls: Label, Button, TextBox, ListBox, ComboBox,


Check Box, Radio Button and their Common Property, Event and
Method:
1) Label:
The label control is used to display a text or a message to the user on the form.
The label control is normally used along with other controls. Common examples
is wherein a label is added along with the textbox control. The label gives an
indication to the user on what is expected to fill up in the textbox.
The Label control represents a standard Windows label. It is generally used to
display some informative text on the GUI which is not changed during runtime.

Creat By : kuldeep padhya


21
Unit – 2 (.Net Framework)

Properties of the Label Control:


Sr.No. Property & Description
1. Autosize: Gets or sets a value specifying if the control should be
automatically resized to display all its contents.
2. BorderStyle: Gets or sets the border style for the control.
3. FlatStyle: Gets or sets the flat style appearance of the Label
control
4. Font: Gets or sets the font of the text displayed by the control
5. FontHeight: Gets or sets the height of the font of the control.
6. ForeColor: Gets or sets the foreground color of the control
7. PreferredHeight: Gets the preferred height of the control.
8. PreferredWidth: Gets the preferred width of the control
9. TabStop: Gets or sets a value indicating whether the user can tab
to the Label. This property is not used by this class.
10. Text: Gets or sets the text associated with this control.
11. TextAlign: Gets or sets the alignment of text in the label.

Methods of the Label Control:


Sr.No. Method Name & Description
1. GetPreferredSize: Retrieves the size of a rectangular area into
which a control can be fitted.
2. Refresh: Forces the control to invalidate its client area and
immediately redraw itself and any child controls.
3. Select: Activates the control.
4. Show: Displays the control to the user.
5. ToString: Returns a String that contains the name of the control.

Creat By : kuldeep padhya


22
Unit – 2 (.Net Framework)

Events of the Label Control:


Sr.No. Event & Description
1. AutoSizeChanged: Occurs when the value of the AutoSize
property changes.
2. Click: Occurs when the control is clicked.
3. DoubleClick: Occurs when the control is double-clicked.
4. GotFocus: Occurs when the control receives focus.
5. Leave: Occurs when the input focus leaves the control.
6. LostFocus: Occurs when the control loses focus.
7. TabIndexChanged: Occurs when the TabIndex property value
changes.
8. TabStopChanged: Occurs when the TabStop property changes.
9. TextChanged: Occurs when the Text property value changes.

2) TextBox:
A text box is used for allowing a user to enter some text on the Web form
application. Let’s see how we can implement this with an example shown below.
We will add one textbox to the form in which the user can enter his name.
Text box controls allow entering text on a form at runtime. By default, it takes a
single line of text, however, you can make it accept multiple texts and even add
scroll bars to it.

Creat By : kuldeep padhya


23
Unit – 2 (.Net Framework)

The Properties of the TextBox Control:


Sr.No. Property & Description
1. AcceptsReturn: Gets or sets a value indicating whether pressing
ENTER in a multiline TextBox control creates a new line of text in
the control or activates the default button for the form.
2. AutoCompleteCustomSource: Gets or sets a custom
System.Collections.Specialized.StringCollection to use when the
AutoCompleteSourceproperty is set to CustomSource.
3. AutoCompleteMode: Gets or sets an option that controls how
automatic completion works for the TextBox.
4. AutoCompleteSource: Gets or sets a value specifying the source
of complete strings used for automatic completion.
5. CharacterCasing: Gets or sets whether the TextBox control
modifies the case of characters as they are typed.
6. Font: Gets or sets the font of the text displayed by the control
7. FontHeight: Gets or sets the height of the font of the control.
8. ForeColor: Gets or sets the foreground color of the control.
9. Lines: Gets or sets the lines of text in a text box control.
10. Multiline: Gets or sets a value indicating whether this is a multiline
TextBox control.
11. PasswordChar: Gets or sets the character used to mask characters
of a password in a single-line TextBox control.
12. ReadOnly: Gets or sets a value indicating whether text in the text
box is read-only.
13. ScrollBars: Gets or sets which scroll bars should appear in a
multiline TextBox control. This property has values −
▪ None
▪ Horizontal
▪ Vertical
▪ Both

Creat By : kuldeep padhya


24
Unit – 2 (.Net Framework)
14. TabIndex: Gets or sets the tab order of the control within its
container.
15. Text: Gets or sets the current text in the TextBox
16. TextAlign: Gets or sets how text is aligned in a TextBox control.
This property has values −
▪ Left
▪ Right
▪ Center
17. TextLength: Gets the length of text in the control.
18. WordWrap: Indicates whether a multiline text box control
automatically wraps words to the beginning of the next line when
necessary.

The Methods of the TextBox Control:


Sr.No. Method & Description
1. AppendText: Appends text to the current text of a text box.
2. Clear Clears: all text from the text box control.
3. Copy: Copies the current selection in the text box to the
Clipboard.
4. Cut: Moves the current selection in the text box to the Clipboard..
5. Paste: Replaces the current selection in the text box with the
contents of the Clipboard.
6. Paste(String): Sets the selected text to the specified text without
clearing the undo buffer.
7. ResetText: Resets the Text property to its default value.
8. ToString: Returns a string that represents the Textbox Base
control.
9. Undo: Undoes the last edit operation in the text box.

Events of the TextBox Control:


Sr.No. Method & Description
1. Click Occurs when the control is clicked
2. DoubleClick Occurs when the control is double-clicked.
3. DoubleClick Occurs when the control is double-clicked.

Creat By : kuldeep padhya


25
Unit – 2 (.Net Framework)

3) Button:
C# Button class in .NET Framework class library represents a Windows Forms
Button control. A Button control is a child control placed on a Form and used to
process click event and can be clicked by a mouse click or by pressing ENTER
The Button control represents a standard Windows button. It is generally used to
generate a Click event by providing a handler for the Click event.

Creat By : kuldeep padhya


26
Unit – 2 (.Net Framework)

The Properties of the Button Control:


Sr.No. Property & Description
1. AutoSizeMode: Gets or sets the mode by which the Button
automatically resizes itself.
2. BackColor: Gets or sets the background color of the control.
3. BackgroundImage: Gets or sets the background image displayed in
the control.
4. DialogResult: Gets or sets a value that is returned to the parent form
when the button is clicked. This is used while creating dialog boxes.
5. ForeColor: Gets or sets the foreground color of the control.
6. Image: Gets or sets the image that is displayed on a button control.
7. Location: Gets or sets the coordinates of the upper-left corner of the
control relative to the upper-left corner of its container.
8. TabIndex: Gets or sets the tab order of the control within its container.
9. Text: Gets or sets the text associated with this control.

The Methods of the Button Control:


Sr.No. Method & Description
1. GetPreferredSize: Retrieves the size of a rectangular area into
which a control can be fitted.
2. NotifyDefault: Notifies the Button whether it is the default button so
that it can adjust its appearance accordingly.
3. Select: Activates the control.
4. ToString: Returns a String containing the name of the Component,
if any. This method should not be overridden.

Creat By : kuldeep padhya


27
Unit – 2 (.Net Framework)

Events of the Button Control:


Sr.No. Method & Description
1. Click: Occurs when the control is clicked.
2. DoubleClick: Occurs when the user double-clicks the Button control.
3. GotFocus: Occurs when the control receives focus.
4. TabIndexChanged: Occurs when the TabIndex property value
changes.
5. TextChanged: Occurs when the Text property value changes.
6. Validated: Occurs when the control is finished validating.

4) List Box:
Listbox in C# provides an interface for the user to display multiple list items. The
user could select single or multiple elements from the list by clicking elements.
These elements are generally displayed in multiple columns instead of a straight
vertical list.
It allows the programmer to add items at design time by using the properties
window or at the runtime.

Creat By : kuldeep padhya


28
Unit – 2 (.Net Framework)

The Properties of the Listbox Control:


Sr.No. Property & Description
1. AllowSelection: Gets a value indicating whether the ListBox
currently enables selection of list items.
2. BorderStyle: Gets or sets the type of border drawn around the list
box.
3. ColumnWidth: Gets of sets the width of columns in a multicolumn
list box.
4. HorizontalExtent: Gets or sets the horizontal scrolling area of a list
box.
5. HorizontalScrollBar: Gets or sets the value indicating whether a
horizontal scrollbar is displayed in the list box.
6. ItemHeight: Gets or sets the height of an item in the list box.
7. Items: Gets the items of the list box.
8. MultiColumn: Gets or sets a value indicating whether the list box
supports multiple columns.
9. ScrollAlwaysVisible: Gets or sets a value indicating whether the
vertical scroll bar is shown at all times.
10. SelectedIndex: Gets or sets the zero-based index of the currently
selected item in a list box.
11. SelectedIndices: Gets a collection that contains the zero-based
indexes of all currently selected items in the list box.
12. SelectedIndices: Gets a collection that contains the zero-based
indexes of all currently selected items in the list box.
13. SelectedItems: Gets a collection containing the currently selected
items in the list box.
14. SelectedValue: Gets or sets the value of the member property
specified by the ValueMember property.
15. SelectionMode: Gets or sets the method in which items are
selected in the list box. This property has values −
▪ None
▪ One
▪ MultiSimple
▪ MultiExtended
16. Sorted: Gets or sets a value indicating whether the items in the list
box are sorted alphabetically.
17. Text: Gets or searches for the text of the currently selected item in
the list box.
18. TopIndex: Gets or sets the index of the first visible item of a list box.

Creat By : kuldeep padhya


29
Unit – 2 (.Net Framework)

The Methods of the Listbox Control:


Sr.No. Method & Description
1. BeginUpdate: Prevents the control from drawing until the EndUpdate
method is called, while items are added to the ListBox one at a time.
2. ClearSelected: Unselects all items in the ListBox.
3. EndUpdate: Resumes drawing of a list box after it was turned off by
the BeginUpdate method.
4. FindString: Finds the first item in the ListBox that starts with the
string specified as an argument.
5. FindStringExact: Finds the first item in the ListBox that exactly
matches the specified string.
6. GetSelected: Returns a value indicating whether the specified item is
selected.
7. SetSelected: Selects or clears the selection for the specified item in a
ListBox.
8. OnSelectedIndexChanged: Raises the SelectedIndexChanged event.
9. OnSelectedValueChanged: Raises the SelectedValueChanged event.

Events of the Listbox Control:


Sr.No. Method & Description
1. Click: Occurs when a list box is selected.
2. SelectedIndexChanged: Occurs when the SelectedIndex property of
a list box is changed.

Creat By : kuldeep padhya


30
Unit – 2 (.Net Framework)

5) CheckBox:
The CheckBox control is the part of windows form which is used to take input
from the user. Or in other words, CheckBox control allows us to select single or
multiple elements from the given list or it can provide us options like yes or no,
true or false, etc. It can be displayed as an image or text or both.

The Properties of the Checkbox Control:

Creat By : kuldeep padhya


31
Unit – 2 (.Net Framework)
Sr.No. Property & Description
1. AllowSelection: Gets a value indicating whether the list enables
selection of list items.
2. AutoCompleteCustomSource: Gets or sets a custom
System.Collections .Specialized.StringCollection to use when the
AutoCompleteSourceproperty is set to CustomSource.
3. AutoCompleteMode: Gets or sets an option that controls how
automatic completion works for the ComboBox.
4. AutoCompleteSource: Gets or sets a value specifying the source of
complete strings used for automatic completion.
5. DataBindings: Gets the data bindings for the control.
6. DataManager: Gets the CurrencyManager associated with this
control.
7. DataSource: Gets or sets the data source for this ComboBox.
8. DropDownHeight: Gets or sets the height in pixels of the drop-down
portion of the ComboBox.
9. DropDownStyle: Gets or sets a value specifying the style of the
combo box.
10. DropDownWidth: Gets or sets the width of the of the drop-down
portion of a combo box.
11. DroppedDown: Gets or sets a value indicating whether the combo
box is displaying its drop-down portion.
12. FlatStyle: Gets or sets the appearance of the ComboBox.
13. ItemHeight: Gets or sets the height of an item in the combo box
14. Items: Gets an object representing the collection of the items
contained in this ComboBox.
15. MaxDropDownItems: Gets or sets the maximum number of items to
be displayed in the dropdown part of the combo box.
16. MaxLength: Gets or sets the maximum number of characters a user
can enter in the editable area of the combo box.
17. SelectedIndex: Gets or sets the index specifying the currently selected
item.
18. SelectedItem: Gets or sets currently selected item in the ComboBox.
19. SelectedText: Gets or sets the text that is selected in the editable
portion of a ComboBox.
20. SelectedValue: Gets or sets the value of the member property
specified by the ValueMember property.
21. SelectionLength: Gets or sets the number of characters selected in the
editable portion of the combo box.
22. SelectionStart: Gets or sets the starting index of text selected in the
combo box.

Creat By : kuldeep padhya


32
Unit – 2 (.Net Framework)
23. Sorted: Gets or sets a value indicating whether the items in the combo
box are sorted.
24. Text: Gets or sets the text associated with this control. Gets or sets the
text associated with this control.

The Methods of the Checkbox Control:


Sr.No. Method & Description
1. BeginUpdate: Prevents the control from drawing until the
EndUpdate method is called, while items are added to the combo
box one at a time.
2. EndUpdate: Resumes drawing of a combo box, after it was turned
off by the BeginUpdate method.
3. FindString: Finds the first item in the combo box that starts with
the string specified as an argument.
4. FindStringExact: Finds the first item in the combo box that exactly
matches the specified string.
5. SelectAll: Selects all the text in the editable area of the combo box.

Events of the Checkbox Control:


Sr.No. Method & Description
1. DropDown: Occurs when the drop-down portion of a combo box is
displayed.
2. DropDownClosed: Occurs when the drop-down portion of a combo
box is no longer visible.
3. DropDownStyleChanged: Occurs when the DropDownStyle
property of the ComboBox has changed.
4. SelectedIndexChanged: Occurs when the SelectedIndex property of
a ComboBox control has changed.
5. SelectionChangeCommitted: Occurs when the selected item has
changed and the change appears in the combo box.

6) Radiobutton:

Creat By : kuldeep padhya


33
Unit – 2 (.Net Framework)
A radio button or option button enables the user to select a single option from a
group of choices when paired with other RadioButton controls. When a user
clicks on a radio button, it becomes checked, and all other radio buttons with
same group become unchecked.
“A Radio button is used to showcase a list of items out of which the user can
choose one”.
In C#, RadioButton is a class and it is defined under System.Windows.Forms
namespace. In RadioButton, you are allowed to display text, image, or both and
when you select one radio button in a group other radio buttons automatically
clear.
The RadioButton control is used to provide a set of mutually exclusive options.
The user can select one radio button in a group. If you need to place more than
one group of radio buttons in the same form, you should place them in different
container controls like a GroupBox control.

The Properties of the Radiobutton Control:

Creat By : kuldeep padhya


34
Unit – 2 (.Net Framework)
Sr.No. Property & Description
1. Appearance: Gets or sets a value determining the appearance of the
radio button.
2. AutoCheck: Gets or sets a value indicating whether the Checked
value and the appearance of the control automatically change when
the control is clicked.
3. CheckAlign: Gets or sets the location of the check box portion of
the radio button.
4. Checked: Gets or sets a value indicating whether the control is
checked.
5. Text: Gets or sets the caption for a radio button.
6. TabStop: Gets or sets a value indicating whether a user can give
focus to the RadioButton control using the TAB key.

The Methods of the Radiobutton Control:


Sr.No. Method & Description
1. PerformClick: Generates a Click event for the control, simulating a
click by a user.

Events of the Radiobutton Control:


Sr.No. Method & Description
1. AppearanceChanged Occurs when the value of the Appearance
property of the RadioButton control is changed.
2. CheckedChanged Occurs when the value of the Checked property of
the RadioButton control is changed

Creat By : kuldeep padhya

You might also like