Building Rich Client Experience - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Building Rich Client Experience

Description:

... browser's dynamic HTML to create rich UI. Require ... How to Create an Inherited Form ... How to Create MDI Applications. How Parent and Child Forms Interact ... – PowerPoint PPT presentation

Number of Views:270
Avg rating:3.0/5.0
Slides: 46
Provided by: downloadM
Category:

less

Transcript and Presenter's Notes

Title: Building Rich Client Experience


1
Building Rich Client Experience
2
Lesson Creating a Form
  • Windows Forms vs. Web Forms
  • How to Create a Form
  • How to Set Form Properties
  • Form Life Cycle
  • How to Handle Form Events
  • Windows Form Designer-Generated Code

3
Windows Forms vs. Web Forms
4
How to Create a Form
  • A base form is created when you create a new
    project
  • To create a new form
  • 1. Right-click the project in Solution Explorer
  • 2. Click Add
  • 3. Click Add Windows Forms

5
How to Set Form Properties
6
Form Life Cycle
1. Form1 Show
5. Form2 Load
7. Form2 GotFocus
4. Form2 Show
2. Form1 Load
8. Form2 Activated
3. Form1 Activated
10. Form2 LostFocus
6. Form1 Deactivate
9. Focus shifts back to Form1
11. Form2 Deactivate
12. Form1 Activated
13. Close Form2
14. Form1 Deactivate
15. Form2 GotFocus
21. Form1 Activated
16. Form2 Activated
17. Form2 Closing
24. Form1 Closing
23. Exit Application
18. Form2 Closed
25. Form1 Closed
19. Form2 LostFocus
26. Form1 LostFocus
20. Form2 Deactivate
27. Form1 Deactivate
22. Form2 Disposed
28. Form1 Disposed
7
How to Handle Form Events
Events
8
Windows Forms Designer-Generated Code
9
Lesson Adding Controls to a Form
  • How to Add Controls to a Form
  • How to Add Menus to a Form
  • How to Customize the Controls Toolbox
  • Practice Creating a Form and Adding Controls

10
How to Add Controls to a Form
11
How to Add Menus to a Form
12
How to Customize the Controls Toolbox
13
Lesson Creating an Inherited Form
  • Access Modifiers
  • How to Create an Inherited Form

14
Access Modifiers
15
How to Create an Inherited Form
Create an inherited form by using the Inheritance
Picker dialog box
Create an inherited form programmatically
public class Form2 Namespace1.Form1
16
Lesson Organizing Controls on a Form
  • How to Arrange Controls on a Form by Using the
    Format Menu
  • How to Set the Tab Order for Controls
  • How to Anchor a Control in Windows Forms
  • How to Dock a Control in Windows Forms

17
How to Arrange Controls on a Form by Using the
Format Menu
18
How to Set the Tab Order for Controls
  • To set the tab order for controls
  • On the View menu, select Tab Order
  • Click a control to change its tab order
  • -- OR --
  • Set the TabIndex property
  • Set the TabStop property to True

19
How to Anchor a Control in Windows Forms
  • Anchoring
  • Ensures that the edges of the control remain in
    the same position with respect to the parent
    container
  • To anchor a control to the form
  • Set its Anchor property
  • Default value Top, Left
  • Other Styles Bottom, Right

20
How to Dock a Control in Windows Forms
  • Docking
  • Enables you to glue the edges of a control to the
    edges of its parent control
  • To dock a control
  • Set the Dock property

21
Lesson Creating MDI Applications
  • SDI vs. MDI Applications
  • How to Create MDI Applications
  • How Parent and Child Forms Interact
  • Practice Creating an MDI Application

22
SDI vs. MDI Applications
SDI
MDI
Only one document is visible
Displays multiple documents at the same time
You must close one document before you open
another
Each document is displayed in its own window
23
How to Create MDI Applications
  • To create a parent form
  • Create a new project
  • Set the IsMdiContainer property to True
  • Add a menu item to invoke the child form
  • To create a child form
  • Add a new form to the project
  • To call a child form from a parent form

protected void MenuItem2_OnClick(object sender,
System.EventArgs e) Form2 NewMdiChild new
Form2() // Set the Parent Form of the Child
window. NewMdiChild.MdiParent this // D
isplay the new form. NewMdiChild.Show()
24
How Parent and Child Forms Interact
  • To list the available child windows that are
    owned by the parent
  • Create a menu item (Windows) and set its MdiList
    property to True
  • To determine the active MDI child
  • Use the ActiveMdiChild property
  • To arrange child windows on the parent form
  • Call the LayoutMdi method

Form activeChild this.ActiveMdiChild
25
Lesson Adding ADO.NET Objects to and Configuring
ADO.NET Objects in a Windows Forms Application
  • ADO.NET Objects
  • What Is a DataSet?
  • What Is a Typed DataSet?
  • How to Add ADO.NET Objects to and Configure
    ADO.NET Objects in a Windows Forms Application

26
ADO.NET Objects
DataSet
DataAdapter
Data Source
DataTable
SelectCommand
Fill
Update
Connection
UpdateCommand
DataAdapter
DataTable
SelectCommand
Fill
Update
UpdateCommand
27
What Is a DataSet?
  • Datasets can include multiple DataTables
  • Relationships between tables are represented
    using DataRelations
  • Constraints enforce primary and foreign keys
  • Use the DataRow and DataColumn to access values
    in Tables

DataColumn
DataRow
DataTable
DataRelation
28
What Is a Typed DataSet?
  • Typed datasets
  • Derive from the base DataSet class
  • Provide type checking at compile time
  • Provide faster access to tables and columns in
    the dataset
  • Generated from XML Schema (.xsd) files by using
    the XSD.exe tool
  • To access tables and columns
  • Untyped dataset

PubsDataSet.Tables("Titles")
  • Typed dataset

PubsDataSet.Titles
29
How to Add ADO.NET Objects to and Configure
ADO.NET Objects in a Windows Forms Application
30
Lesson Accessing and Modifying Data by Using
DataSets
  • How to Populate a Dataset
  • How to Update Data in a Dataset
  • How to Update Data to a Data Source
  • How to Create Database Schema on the Client
  • How to Read and Write XML Data into a DataSet

31
How to Populate a Dataset
  • Use the DataAdapter object to fill the dataset

SqlDataAdapter storesSQLDataAdapter
SqlCommand storesSelectSQLCommand
storesSelectSQLCommand.CommandText "SELECT
FROM stores" storesSelectSQLCommand.Connection
SqlConnection1 storesSQLDataAdapter.SelectComma
nd storesSelectSQLCommand storesSQLDataAdapter
.Fill(storesDataSet.Tables"Stores")
32
How to Update Data in a DataSet
  • Adding rows
  • Editing rows
  • Deleting data

DataRow newDataRow pubsDataSet.Tables"Titles"
.NewRow() newDataRow"title" "New Book" new
DataRow"type" "business" pubsDataSet.Tables
"Titles".Rows.Add(newDataRow)
changeDataRow.BeginEdit( ) changeDataRow"Title"
changeDataRow"Title".ToString() " 1"
changeDataRow.EndEdit( )
DataRow deleteDataRow pubsDataSet.Tables"Titles
".Rows0 pubsDataSet.Tables"Titles".Rows.Rem
ove(deleteDataRow)
33
How to Update Data to a Data Source
  • Explicitly specifying the updates

SqlCommand insertTitlesCommand new SqlCommand
("Insert titles (title_id, title, type)
values (_at_title_id,_at_title,_at_type)")
insertTitlesCommand.Parameters.Add ("_at_title_id
", SqlDbType.VarChar, 6, "title_id")
insertTitlesCommand.Parameters.Add
("_at_title", SqlDbType.VarChar, 80, "title")
insertTitlesCommand.Parameters.Add
("_at_type", SqlDbType.Char, 12, "type")
titlesSQLDataAdapter.InsertCommand insertTitle
sCommand titlesSQLDataAdapter.Update(pubsDataSet
, "titles")
34
How to Create Database Schema on the Client
  • XML Schema (.xsd) files enforce data integrity on
    the client
  • Use the XML Designer to create and modify XML
    Schema files
  • 1. Determine the schema design
  • 2. On the Project menu, click Add New Item
  • 3. Add the schema
  • 4. Create the schema

35
How to Read and Write XML Data into a DataSet
  • Use ReadXML to load data from a file or stream
  • Write data and schema information from a DataSet
    to a file or stream by using the WriteXML method

purchaseDataSet.ReadXml ("C\\sampledata\\Purch
aseData.xml",
XmlReadMode.IgnoreSchema)
purchaseDataSet.WriteXml ("C\\sampledata\\Curren
tOrders.xml", XmlWriteMode.IgnoreSchema)
36
Lesson Binding Data to Controls
  • How to Perform Simple Binding by Using the
    DataBindings Property
  • How to Perform Complex Data Binding by Using the
    DataBound Windows Forms Controls
  • How to Maintain the Currency of a Control by
    Using CurrencyManager
  • How to Format and Parse Data Bound Values

37
How to Perform Simple Binding by Using the
DataBindings Property
To use the DataBindings Collection to bind a
control to a data source, set the DataBinding
property of the control to the data source
38
How to Perform Complex Data Binding by Using the
DataBound Windows Forms Controls
  • Complex data binding
  • Bind a control property to a data table
  • Use with combo boxes, list boxes, data grids
  • Can bind controls to DataSets, Arrays, and
    ArrayLists
  • Complex databinding at design time
  • Set the DataSource and DataMember properties
  • Complex databinding at run time

DataGrid1.DataSource productsDataSet
DataGrid1.DataMember "Products"
39
How to Maintain the Currency of a Control by
Using CurrencyManager
TextBox1
Currency Manager1
TextBox2
Data Source 1
Currency Manager2
Datagrid
Data Source 2
CurrencyManager cm cm (CurrencyManager)this.Bi
ndingContextpubsDataSet, "Authors" cm.Positi
on 1
40
How to Format and Parse Data Bound Values
10
10
TextBox1
Format
10
Parse
10
Binding Object
Data Source
41
Lesson Persisting Data
  • How to Persist Data in Files
  • How to Serialize Objects
  • How to Persist Application Settings

42
How to Persist Data in Files
  • Use readers and writers for persisted
    data

43
How to Serialize Objects
  • Binary serialization
  • XML serialization

44
How to Persist Application Settings
  • Choose a technique
  • Use a DataSet object
  • Good for tabular or relational data
  • Use reader/writer objects
  • Complete control, but developer must writeand
    maintain more code
  • Use serialization
  • Good choice when application stores state in
    objects
  • Choose a storage location
  • The file system

45
Questions?
Write a Comment
User Comments (0)
About PowerShow.com