1 / 45

Building Rich Client Experience

Building Rich Client Experience. 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. Feature. Windows Forms. Web Forms. Deployment.

linus
Télécharger la présentation

Building Rich Client Experience

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Feature Windows Forms Web Forms Deployment Can be run without altering the registry No download required Graphics Includes GDI+ Interactive or dynamic graphics require round trips to the server for updates Responsiveness Provide the quickest response speed for interactive applications Can take advantage of the browser's dynamic HTML to create rich UI Platform Requires .NET Framework running on the client computer Require only a browser Programming model Based on a client-side, Win32-based message-pump mode Applications components are invoked via HTTP Security Code-based and role-based security Role-based security 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. Events Button Form Name Categorized Button Alphabetic Button Description Pane 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. Right-click the Toolbox 1 Click Customize Toolbox 2 Select the required control on the .NET Framework Components page 3 How to Customize the Controls Toolbox

  13. Lesson: Creating an Inherited Form • Access Modifiers • How to Create an Inherited Form

  14. Access Modifier Description Private Read-only to a child form, all of its property values in the property browser are disabled Protected Accessible within the class and from any class that inherits from the class that declared this member Public Most permissive level. Public controls have full accessibility 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; // Display 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. Drag an OleDbDataAdapter or SqlDataAdapter object from the Toolbox to a form 1 Specify connection and SQL command information 2 Select the adapter or adapters that will be used to transfer data between the data source and the dataset 3 On the Data menu, choose Generate Dataset 4 Select New and then specify a name for the new dataset 5 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.SelectCommand = 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"; newDataRow["type"] = "business"; pubsDataSet.Tables["Titles"].Rows.Add(newDataRow); changeDataRow.BeginEdit( ); changeDataRow["Title"] = changeDataRow["Title"].ToString() + " 1"; changeDataRow.EndEdit( ); DataRow deleteDataRow = pubsDataSet.Tables["Titles"].Rows[0]; pubsDataSet.Tables["Titles"].Rows.Remove(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 (@title_id,@title,@type)"); insertTitlesCommand.Parameters.Add ("@title_id", SqlDbType.VarChar, 6, "title_id"); insertTitlesCommand.Parameters.Add ("@title", SqlDbType.VarChar, 80, "title"); insertTitlesCommand.Parameters.Add ("@type", SqlDbType.Char, 12, "type"); titlesSQLDataAdapter.InsertCommand = insertTitlesCommand; 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\\PurchaseData.xml", XmlReadMode.IgnoreSchema); purchaseDataSet.WriteXml ("C:\\sampledata\\CurrentOrders.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. Property of the control to which data is bound txtCustomerAddress.DataBindings.Add("Text", dsNorthwindData1.Customers, "Address"); txtCustomerCity.DataBindings.Add("Text", dsNorthwindData1.Customers, "City"); Table from the data source Column in the table 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.BindingContext[pubsDataSet, "Authors"]; cm.Position += 1;

  40. How to Format and Parse Data Bound Values 10 $10 Format TextBox1 10 Parse $10 Data Source Binding Object

  41. Lesson: Persisting Data • How to Persist Data in Files • How to Serialize Objects • How to Persist Application Settings

  42. Class Description BinaryReader and BinaryWriter These classes read and write primitive types as binary values in a specific encoding to and from a stream. StreamReader and StreamWriter The implementations of these classes are designed for character input and output. StringReader and StringWriter The implementations of these classes are designed for string input and output. How to Persist Data in Files • Use readers and writers for persisted data

  43. Add the Serializable attribute Serialize the object to a file 1 1 Serialize the object to a file Deserialize the file into an object 2 2 Deserialize the file into an object 3 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?

More Related