[go: up one dir, main page]

0% found this document useful (0 votes)
26 views28 pages

Unit III - C# - 2022 - 23

The document provides an overview of the Integrated Development Environment (IDE) in Visual Studio .Net, detailing its components such as the menu bar, toolbars, and various windows like the solution explorer and error list. It also explains how to create a Windows Forms Application and describes controls like Label, TextBox, Button, ListBox, ComboBox, PictureBox, and Timer, including their properties, methods, and events. This serves as a guide for developing user interactive applications using Visual Studio 2010.

Uploaded by

sayyed.mht
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)
26 views28 pages

Unit III - C# - 2022 - 23

The document provides an overview of the Integrated Development Environment (IDE) in Visual Studio .Net, detailing its components such as the menu bar, toolbars, and various windows like the solution explorer and error list. It also explains how to create a Windows Forms Application and describes controls like Label, TextBox, Button, ListBox, ComboBox, PictureBox, and Timer, including their properties, methods, and events. This serves as a guide for developing user interactive applications using Visual Studio 2010.

Uploaded by

sayyed.mht
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/ 28

Unit III (Chapter 5)

 Integrated Development Environment (IDE)

To simplify the process of application development, Visual Studio .Net provides an environment
that is common for all .net languages is called Integrated Development Environment (IDE).

The IDE provides the tools for designing, executing and debugging applications.

To access Visual Studio IDE:

Click on Start buttonselect ProgramsMicrosoft Visual Studio 2010Microsoft Visual


Studio 2010.

It will show the Microsoft Visual Studio IDE as shown below:

Figure (1) Integrated Development Environment (IDE)


The IDE consists of the following components:

1. Menu bar 4. The properties window

2. Toolbar 5. The solution explorer window

3. The toolbox window 6. The Error list window

1. Menu bar: provides various menus with submenus as follows:

File menu: contains commands to open new or old project, to save project and many other
options.

View menu: contains commands to display any toolbar or window of the IDE

Project menu: contains commands for adding items to the current project

Build menu: contains commands for building (compiling) project

Debug menu: contains commands to start and end an application as well as the basic debugging
tools

2. Toolbar: Toolbars provides quick access to the menu items.

Ex. Standard toolbar provides most of the functionality options

3. The toolbox window

The Toolbox window displays controls that we can add to Visual Studio projects. To open
Toolbox, choose Toolbox on the View menu.

We can drag and drop different controls onto the surface of the form, resize and position the
controls.

4. The properties window

This window is also known as the property browser. It displays all the properties of the selected
component and their settings.

The properties window is divided into columns, with the properties on the left and their settings
on the right. When we click on a particular control then it will open all the properties of it in the
properties window.

5. The solution explorer window

This window contains a list of the items in the current solution. A solution may contain multiple
projects and each project may contain multiple items. The solution explorer displays a
hierarchical list of all the components, organized by project. You can right click any component
of the project and select properties in the context menu to see the selected components.

6. The ErrorList window

This window is usually populated by the compiler with error messages, if the code can’t be
successfully compiled. We can double-click an error message in this window and the IDE will go
the line with the statement in error which you should fix.

7. Form designer window

8. Code window

7. The start page:

When you open .Net studio for the first time, you will see the window as shown below:

Figure(2) Start page

The start page displays the list of recently opened projects as well as the New project and Open
project buttons.

The remaining options lead to Visual Studio sites with up-to-date information about the product,
such as news articles, updated documents and service packs or patches.
 Building Windows Application with Visual Studio:

Windows Forms Application project type is used to develop an user interactive application for
database handling, for creating calculator, for creating application like Word, Notepad etc.

Steps to create Windows Forms Application

Start buttonProgramsMicrosoft Visual Studio 2010Microsoft Visual Studio


2010File menuSelect New Projectselect Visual C# select Windows Forms
applicationEnter project name, location and solution name in the bottom of dialog
boxclick on Ok button

It will open a Form designer window and all other IDE components.

Double clock on the Form1, it will open the code window as follows:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, KeyPressEventArgs e)


{

MessageBox.Show("First C# Windows application");


}

}
}
 Label control

Label control is used to display the text that cannot be modified by the user.

Label control properties:

Property setting
Property name and use
Design time Run time
Name
Represents a unique name of a label
control which can be accessed in the Name=lbl_result label1.Name = “lbl_result";
code.
Default name for label control is
“label1”
Location Location=20,50 label1.Location=new
Specifies the starting position of the Point(20,50);
label control on a form.
Size
Specifies the size of the label label1.Height=50;
control. Size=50,80 label1.Width=80;
We can also use Height and Width
property instead of Size property
BackColor
Set background color of label control label1.BackColor=Color.Red;

ForeColor
Set foreground color of label control label1.ForeColor=Color.Blue;

BorderStyle
Set border of a label control.
There are three possible values for BorderStyle=FixedSingle label1.BorderStyle=
this property: BorderStyle.FixedSingle;
 None(default)
 FixedSingle
 Fixed3D

Font Font=font type, font label1.Font=new Font(“Times


Represents the font of text of a Label style and font size New Roman”,12);
control

Text Text=Calculator label1.Text=”Calculator”;


Represents the current text of a label
control
TextAlign
Represents text alignment that can TextAlign= TopCenter
be:
TopLeft, TopCenter, TopRight,
MiddleLeft, MiddleCenter,
MiddleRight, BottomLeft,
BottomCenter, BottomRight

-Autosize need to be set to False


Image Image: Browse button label1.Image=Image.FromFile
Set a label background an image (“d:\mypictures\logo.jpg”);

 TextBox Control

A TextBox control is used accept an input from the user or to display text. It is an editable
control as it allows the user to edit the text within it.

 TextBox control properties:

Property name and use Property setting


Design time Run time
Name
Represents unique name of a
textbox control which can be textBox1.Name = “txt_result";
Name=txt_result
used in code.
Default name for textbox control
is “textBox1”.
Text Text=Welcome
textBox1.Text = "Welcome";

CharacterCasing
Set Character Case.
There are three possible values
for this property: CharacterCasing=Upper

-Normal(default): The case of


characters is left unchanged.

-Upper : Converts all characters


to uppercase.

-Lower: Converts all characters


to lowercase.
MaxLength textBox1.MaxLength = 8;
Set maximum number of MaxLength=50
characters to be entered in a
textbox.
Default value is 32767
MultiLine textBox1.Multiline = true;
Allows multiple lines of text. MultiLine=True
To enter more than one line in in
textbox control, set the MultiLine
property to true.
There are two possible values for
this property that is:
 True
 False(default)
Enabled Enabled=False textBox1.Enabled = false;

There are two possible values for


this property that is:
 True(default)
 False
If Enabled property is set to false,
the textbox can not be clicked or
receive focus.
ReadOnly ReadOnly=true textBox1.ReadOnly = true;
When you want to prevent a user
from changing the text that
appears in a textbox, then set
ReadOnly property to true.
There are two possible values for
this property that is:
 True(default)
 False

PasswordChar PasswordChar = * textBox1.PasswordChar = '*';


Specifies the character used to
mask characters of a password

ScrollBars
Specifies which scroll bars
ScrollBars=Both
should appear in a multiline
TextBox control.
There are four possible values for
this property. These are:
 None(default)
 Horizontal
 Vertical
 Both

 TextBox control methods:

1. Focus(): This method is used to set focus to a textbox control.

Example: textBox1.Focus();

2. Clear(): This method is used to clear all text from the textbox.

Example: textBox1.Clear();

 TextBox control events:

1. TextChanged: This event occurs if the Text property is changed by either through program
modification or user input. This is the default event of textbox control.

2. Enter: This event occurs when the control becomes the active control of the form.

3. Leave: This event occurs when the control is no longer the active control of the form.

4. Keypress: This event occurs when a key is pressed.


Example:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
MessageBox.Show("Text is changed");
}
private void textBox2_Enter(object sender, EventArgs e)
{
MessageBox.Show("textbox2 entered");
}
private void textBox1_Leave (object sender, EventArgs e)
{
MessageBox.Show("textbox1 leaved");
}

}
}

 Button control

Button control is an interactive control that enables users to communicate with an application. It
is generally used to execute code when it is clicked.

 Button control properties:

Property setting
Property name and use
Design time Run time
Name
Represents a unique name of a
button control which can be access Name=btn_result button1.Name = “btn_submit";
the control in the code.
Default name for Label control is
“button1”
Location Location=20,50 button1.Location=new
Specifies the starting position of the Point(20,50);
Button control on a form
Size Size=50,80 button1.Height=50;
Specifies the size of the button button1.Width=80;
control
We can also use Height and Width
property instead of Size property
BackColor button1.BackColor=Color.Red;
Set background color of button
control
ForeColor button1.ForeColor=Color.Green;
Set foreground color of button
control
Font Font=font type,font button1.Font=new Font(“Times
Represents the font of text of a style and font size New Roman”,12);
button control
Text
Represents the current text of a Text=Submit button1.Text=”Submit”;
button control
Enabled Enabled=False button1.Enabled=false;
This property has two possible
values either true or false.
If Enabled property is set to False,
button can not be clicked or receive
focus.
By default Enabled is set to True.
Image Image: Browse button button1.Image=Image.FromFile(“
Set a Button control background as d:\mypictures\logo.jpg”);
an image

Visible button1.Visible=false;
This property determines whether
the button is visible or hidden. By
default value is true.

 Button control events:

1. Click-

This event occurs when a button control is clicked.

private void btnmsg_Click(object sender, EventArgs e)


{
MessageBox.Show("button clicked");
}

2. MouseUp: When the mouse pointer is over the button and a mouse button is released.

3. MouseHover

Ex. private void btnmsg_MouseHover(object sender, EventArgs e)


{
MessageBox.Show("mouse hover");
}
4. Leave: When the button control becomes inactive

5. Enter: Occurs when the button control becomes active control of the form
 ListBox control

This control is used to display list of items .Users can select one or more items from the list.

 ListBox control properties:

1. Name: This property represents unique name of a ListBox control. It is used to access it in
the code.

2. Items: This property is a collection that holds the items on the control. At design time, you
can populate this list through the String Collection Editor. At runtime, you can access and
properties of the Items collection.

3. Enabled: This property is used to decide whether to make the control readonly or not.

4. Visible: This property is used to display or hide control at runtime.

5. Sorted: This is a Boolean property that is it have possible values either True or False. It
displays the items of ListBox in ascending order if sorted property is set to True. By default,
sorted property value is False.

Example: listBox1.Sorted=true;

6. SelectionMode: This property defines how items are selected in a ListBox. This property has
possible values as follows:

1. None-No item can be selected


2. One-Only one item can be selected
3. MultiSimple-allows multiple items selection by clicking mouse on it.
4. MultiExtended- allows multiple items selection by pressing ctrl key, shift key & arrow
keys

7. Count-This property counts the number of items in a ListBox control.

8. SelectedItem-This property is used to set or get the currently selected item.

9. SelectedIndex-This property is used to set or grt the currently selected items index.

10. Text: This property returns the selected text on the control
 ListBox control methods:

1. Add( )-To add items to a list, use Add() method.

Example: listBox1.Items.Add(“C#”);

2. Remove( ): To remove an item from list, use Remove() method

Ex:- listBox1.Items.Remove(listBox1.SelectedItem);

Clear( ) :This method clears or removes all the items from a list.

Ex. listBox1.Items.Clear();

 ComboBox control

A comboBox control is a combination of TextBox and ListBox which enables the user to select
items from a list and enter a new item in a list.

Its drop down list presents a list of items.

 ComboBox control properties

1. Name 2. Items 3. Enabled

4. Visible 5. Sorted

6. DropDownStyle: This property determines the style of ComboBox .It specifies whether the
list is always displayed or whether the list is displayed in a drop down and also specifies whether
new item can be inserted or not.

This property have following possible values :

i)Simple: always displays full list and allows the user to enter new item in a list

ii)DropDown(default)-user can select item from a list and also allow to enter new item

iii)DropDownList-user can only select item from list

7. Count

8. SelectedItem

9. SelectedIndex

10. Text
 ComboBox control methods

1. Add( ) 2.Remove( ) 3. Clear( ) .

 ComboBox events

1. SelectedIndexChanged-

This event fires when you change the selected item in a comboBox. This is default event of
comboBox control.

 PictureBox control

This control is used to display images on Windows forms. The images may be bitmaps, icons,
GIF, JPG etc. formats.

Properties:

1. Name 2. Location, Height, Width, Size

3. BorderStyle 4. BackColor

5. Image -set the Image property to the image that you want to display.

6. SizeMode-set this property to position an image within a PictureBox.

There are five different values of SizeMode property are available:

AutoSize- sizes the PictureBox to the image

CenterImage- center the image in the PictureBox.

Normal-places the upper left corner of the image at upper left in the PictureBox

StretchImage-allows you to stretch the image in code

Zoom-makes image in zoom form.

Example:

private void Form3_Load(object sender, EventArgs e)


{
pictureBox1.Image=Image.FromFile("d:\logo.jpg");
pictureBox1.SizeMode =PictureBoxSizeMode.StretchImage;
}
 Timer control
 The Timer control is used to control and manage events that are time related.
 It is invisible during runtime and it does not allow the user to interact with it.
 It is generally used to set an interval between events, periodic checking, to start a process
at a fixed time schedule, to create a clock, stopwatch etc.
 Using Timer control, we can control programs in milliseconds, seconds, and minutes and
even in hours.

Properties of Timer control

1. Enabled: This property indicates whether the timer raises the Tick event.
Ex. Timer1.Enabled=true;
By default the Enabled property of Timer control is false. So before running the program
,we have to set the Enabled property to true ,then only the timer control starts its function.

2. Interval: This property indicates the interval n which to raise the Tick event.

The timer control allows to set Interval property in milliseconds. That is, 1 second=1000
milliseconds
Ex. Timer1.Interval=5000;
This event will be executed after every second.

Events of timer control:


1. Tick- This event occurs when the interval has elapsed.

Example: To create a simple clock, design the form as follows:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)


{
label1.Text = DateTime.Now.ToString();
}
}
}
Output:

 Creating menus:

Menus are one of the most common elements of the Windows user interface.

a)Creating menus and submenus:

Menus are attached only to forms and they are implemented by using MenuStrip control.

Steps to create menus and submenus:

To add MenuStrip control to a form:

–Select Menus and Toolbars section in toolbox

–Double click on MenuStrip control.

-It will be added to the form at the bottom and its default name is menuStrip1.

-A single menu command will appear on your form

-Its caption will be “Type Here”.

-Select the MenuStrip control and click the caption ”Type Here” and enter the first commands
caption as “File”.

-As soon as you start typing, two more captions appear:

i) One on the same level (representing the second command of the main menu)

ii)another one below the File(representing the first command on the File menu)

-Select the item under File and enter the Open. Again enter the remaining items of the File menu:
Save and Exit and click somewhere on the form.
-All temporary items(the ones with the Type Here caption) will disappear and the menu will be
finalized on the form.

-You can add more items as per the requirement by right clicking one of the existing menu item
and selecting InsertMenuItem

b) Separator bar

Separator bar divide menu items into logical groups. To create a separator bar in a menu:

i)Set the items caption to a dash(-)

ii)Right click the item you want to display below the separator and select InsertSeparator

c) Access keys and shortcut keys

i) Access keys

Access keys allow the user to open a menu by pressing the Alt key and a letter key.

Ex. To open the File menu in Windows applications, you can press Alt+F. F is the File menus
access key. Once the menu is opened, the user can select a command with the arrow keys.

-Access keys are marked with underline.

-To assign an access key to menu items:

Insert the ampersand symbol(&) in front of the character you want to use as access key in the
menu items Text property.

Ex: To assign an access key for Exit menu item ,type & symbol in front of E that is &Exit in the
Text property.

ii) Shortcut keys

Shortcut keys are similar to access keys, but instead of opening a menu, they run a command
when pressed.

Shortcut keys are combinations of the control key and a function or character or digit key.

Ex. The usual shortcut key for the copy command is ctrl+c. To assign a shortcut key to a menu
command:

click on the menu item to which you want set shortcut keyin properties window set the
ShortcutKeys property and press Enter key.

This property allows the user to select modifiers that is ctrl, shift and alt and also a key.
d) Programming menu commands

Menu commands are similar to controls. Each menu item has its own name. They have certain
properties that are used to manipulate them.

Ex. Set the Name property of exit menuitem as mnuExit and write the following code in click
event of mnuExit menuitem as follows:

private void mnuExit_click(object sender,EventArgs e)

Application.Exit();

 Common dialog controls

One of the important tasks in every application is to prompt the user for filename, font names
and sizes or colors to be used by the application.

To do this, C#.Net provides common dialog controls. These are:

1. OpenFileDialog 2.SaveFileDialog

3.FontDialog 4.ColorDialog

1, OpenFileDialog and SaveFileDialog control:

Open and Save are the most widely used common dialog boxes and they are implemented by the
OpenFileDialog and saveFileDialog controls.

To add these controls on a form:

Select Dialogs section in ToolboxDouble click on OpenFileDialog/SaveFileDialog controlIt


will be added at the bottom of form

OpenFileDialog control

This control prompts the user to open a file and allow the user to select a file to open
SaveFileDialog control

This control prompts the user to select a location for saving a file and allow the user to display
the name of the file to save data.

These two dialog controls are nearly identical and most of their properties are common.

Properties of OpenFileDialog and SaveFileDialog

1. InitialDirectory

This property sets the initial directory(folder) in which files are displayed the first time the open
and save dialog boxes are opened.

Ex: openFileDialog1.InitialDirectory=”c:”;

openFileDialog1.ShowDialog();

Ex: saveFileDialog1.InitialDirectory=”c:”;

saveFileDialog1.ShowDialog();

2.Title

By default. the open dialog box will display the word “Open” as a caption in the title bar of it. In
case of save dialog box, the caption on the title bar is “Save in” we can change this with the Title
property.

Ex.: openFileDialog1.Title=”Open a text file”;

saveFileDialog1.Title=”Save a text file”;

3. Filter

Using this property, we can display a list of specific files that can be opened or saved.

To display or save text files, set the Filter property to “Text Files|*.txt”

The pipe symbol separates the description of the files from the actual extension.

Ex: openFileDialog1.Filter=”Text Files|*.txt”;

saveFileDialog1.Filter=”Text Files|*.txt”;
4. Filename: This property returns the path of the file selected by the user on the dialog box.

Ex.: string strfilename;

sfilename=openFileDialog1.Filename;
MesasgeBox.Show(strfilename);

Methods of OpenFileDialog and SaveFileDialog

1. ShowDialog( ): This method is used to show the specified dialog box.

Ex.: openFileDialog1.ShowDialog();
saveFileDialog1.ShowDialog();

2. OpenFile( ):

This method is used to open a file with read only permission when used with the openFileDialog
control.
When this method is used with saveFileDialog control, it saves a file with read-write permission.

 Creating and using MDI applications

Multiple Document Interface (MDI) applications allow multiple documents to be open at the
same time.
-MDI application must have only one parent form and one or more child forms.
-The parent form is the MDI form or MDI container because it contains all child forms.
-The child forms are called as MDI children
-The parent form may not contain controls.
Ex. Visual Studio IDE

MDI applications are in contrast to the SDI (Single Document Interface) which can open only one
document at a time.
Ex. Notepad

Properties required for creating MDI application

1. To make a form as MDI parent form, set its IsMdiContainer property to true.
2. To define a parent form to a child form set MdiParent property to true,
Example: Design the form1 and write the following code:

private void Form1_Load(object sender, EventArgs e)


{
IsMdiContainer=true;
}
private void mnuform2_click(object sender, EventArgs e)
{
Form2 f2=new Form2();
f2.MdiParent=this;
f2.Show();

 DateTimePicker control:

A DateTimePicker control allows users to select a date and time in Windows Forms
applications.

It has two parts:

A label-that displays the selected date

A popup calendar-that allows to select a new date.

Properties:

1. Name

Name property represents a unique name of a DateTimePicker control. It is used to access the
control in the code.

2. Value: holds the selected date and time

dateTimePicker1.Value=DateTime.Today;

The value property contains the current date and time the control is set to.

3. MinDate and MaxDate

MinDate and MaxDate properties are used to set the minimum and maximum value of date and
time can be selected by a control.

MaxDate=31-12-9998(default value)

MinDate=01-01-1753(default value)
4. ShowUpDown

We can also use an up-down control (spin button control) to set the date and time. To enable the
spin button control, we just need to set the ShowUpDown property to true. The following code
snippet sets these properties.

Events :

1. ValueChanged

ValueChanged event is fired when the value of a DateTimePicker control is changed.

Example:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void Form3_Load(object sender, EventArgs e)


{
dateTimePicker1.Value = DateTime.Today;
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)


{
label2.Text = "selected date and time="+dateTimePicker1.Value.ToString();
}
}
}
 ProgressBar control

ProgressBar control is used to represent the progress of a lengthy operation that takes time where
user must wait for the operation to be finished.
OR represent the progress of an operation

Properties:

1. Value:
The value property represents the current value of ProgressBar. The current value of ProgressBar
for minimum value is the color green to show the progress of the control. We can use the value
property to show the progress of an operation.

2. Name: represents unique name of a ProgressBar control

3. Minimum and Maximum: Define range of a ProgressBar control.

4. Step: This property is used to set a value in control that calls the PerformStep() method to
increase the current state of the progress bar by adding a defined step.

Methods:
1. PerformStep(): The PerformStep method increments the value of the progress bar by the
amount specified by the Step property.

Example:

using System;
using System.Windows.Forms;
namespace WindowsFormsApplication31
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnstart_Click(object sender, EventArgs e)


{
pBar.Minimum = 0;
pBar.Maximum = 100;
pBar.V;alue = 0;
pBar.Step = 1;
for (int j = 0; j < 100; j++) //100
{
pBar.PerformStep();
}

}
}
}
 CheckBox control: This control allows the user to make multiple selections from a
number of options. We can click a checkbox to select an option and deselect also by
clicking on it.

Important Properties of CheckBox


Property Description

BackColor This property is used to get or set the background color of the control.

This property is used to get or set a value which determine whether the
Checked CheckBox is in the checked state.

This property is used to get or set the font of the text displayed by the
Font control.

ForeColor This property is used to get or set the foreground color of the control.

Name This property is used to get or set the name of the control.

Text This property is used to get or set the text associated with this control.

This property is used to get or set a value which determine whether the
Visible control and all its child controls are displayed.
Important Events on CheckBox
Event Description

This event occur when the value of the Checked property


CheckedChanged changes.

Example:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string items = String.Empty;

if (chk1.Checked)
items = items + "Pen";

if (chk2.Checked)
items = items + "Pencil";

if (chk3.Checked)
items = items + "book";

MessageBox.Show("You have bought: " + items);

}
}
 GroupBox control

A GroupBox control is a container control that is used to place Windows Forms child controls
in a group. The purpose of a GroupBox is to define user interfaces where we can categorize
related controls in a group.

Properties of GroupBox control

Property Description

BackColor This property is used to get or set the background color of the control.

This property is used to get or set the font of the text displayed by the
Font control.

ForeColor This property is used to get or set the foreground color of the control.

Name This property is used to get or set the name of the control.

Text This property is used to get or set the text associated with this control.

This property is used to get or set a value which determine whether the
Visible control and all its child controls are displayed.
 DataGridView control:

DataGridView control is generally used for showing data from the database.

Example: If you have an Access database connected to C# project then you can show data from
it. The data from the database will be shown in rows and columns of DataGridView control.

This control also shows data from other database management systems like Oracle, MS-SQL
Server, MYSQL etc.

1. BackgroundColor:
This property is used to set background color of DataGridView control.

2. DataSource:
This is the most important property of DataGridView control through which we can show
records of dataset in this control. While using this property we have to specify the dataset.

Example:
dataGridView1.DataSource=ds.Tables[0];

3. Count:
This property returns the count of rows and columns present in DataGridView control.
Example:
MessageBox.Show((dataGridView1.Rows.Count).ToString());
MessageBox.Show((dataGridView1.Columns.Count).ToString());

4. ReadOnly:
This property is used to set a value that indicates whether the user of the program can edit the
cells of the control.
It has two possible values either true or false.

Example: dataGridView1.ReadOnly=true;

5. MultiSelect:

MultiSelect is a Boolean property which allows the user to select more than one cell, column or
row.

Example: dataGridView1.MultiSelect=true;
Program:

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication33
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnrowcount_Click(object sender, EventArgs e)


{
MessageBox.Show((dataGridView1.Rows.Count).ToString());
}
private void btncolumncount_Click(object sender, EventArgs e)
{
MessageBox.Show((dataGridView1.Columns.Count).ToString());
}

private void btnselect_Click(object sender, EventArgs e)


{
dataGridView1.MultiSelect = true;
}

private void Form1_Load(object sender, EventArgs e)


{

this.studentTableAdapter.Fill(this.mydatabase2DataSet1.student);

private void button1_Click(object sender, EventArgs e)


{
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
dataGridView1.Rows.RemoveAt(i);
}
}
}
}
 Introduction to WPF

WPF stands for Windows Presentation Foundation.

WPF is a framework for building Windows applications that allow users to develop rich user
interfaces having 3D animations and rich colors with less code complexity.

It is an ideal platform to deal with various media types.

WPF allows the user to create a skinned user interface.

It allows user to take the benefit of the large .net class library as it is built on .net technology.

The difference between WPF and Windows form is that:

1. WPF is newer framework so it is more in tune with current standards where as Windows
form is older one.
2. WPF is flexible and features rich. You can design very rich applications without coding or
buying controls. Windows form is not so feature rich.

For more details visit: www.guru99.com/wpf-tutorial.html

You might also like