0% found this document useful (0 votes)
30 views31 pages

2555a 01

io

Uploaded by

myx_ro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views31 pages

2555a 01

io

Uploaded by

myx_ro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

Module 1: Introducing Windows Forms

Overview

Creating a Form Adding Controls to a Form Creating an Inherited Form Organizing Controls on a Form

Creating MDI Applications

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

Windows Forms vs. Web Forms


Feature
Deployment

Windows Forms
Can be run without altering the registry Includes GDI+ Provide the quickest response speed for interactive applications

Web Forms
No download required Interactive or dynamic graphics require round trips to the server for updates Can take advantage of the browser's dynamic HTML to create rich UI Require only a browser Applications components are invoked via HTTP Role-based security

Graphics

Responsiveness

Platform Programming model Security

Requires .NET Framework running on the client computer Based on a client-side, Win32-based messagepump mode
Code-based and rolebased security

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

How to Set Form Properties


Events Button Form Name Categorized Button Alphabetic Button

Description Pane

Form Life Cycle


1. Form1 Show 5. Form2 Load 7. Form2 GotFocus

2. Form1 Load
3. Form1 Activated 6. Form1 Deactivate 12. Form1 Activated 14. Form1 Deactivate 21. Form1 Activated 24. Form1 Closing

4. Form2 Show

8. Form2 Activated
10. Form2 LostFocus 11. Form2 Deactivate 15. Form2 GotFocus 16. Form2 Activated

9. Focus shifts back to Form1

13. Close Form2

25. Form1 Closed


26. Form1 LostFocus 27. Form1 Deactivate 28. Form1 Disposed

23. Exit Application

17. Form2 Closing

18. Form2 Closed


19. Form2 LostFocus 20. Form2 Deactivate 22. Form2 Disposed

How to Handle Form Events

Events

Windows Forms Designer-Generated Code

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

How to Add Controls to a Form

How to Add Menus to a Form

How to Customize the Controls Toolbox

Right-click the Toolbox Click Customize Toolbox Select the required control on the .NET Framework Components page

Practice: Creating a Form and Adding Controls


In this practice, you will

Set the properties of the form

Add controls to the form


Set the properties of the controls Implement the button Click event handler

Begin reviewing the objectives for this practice activity

10 min

Lesson: Creating an Inherited Form


Access Modifiers How to Create an Inherited Form Practice: Creating an Inherited Form

Access Modifiers

Access Modifier

Description Read-only to a child form, all of its property values in the property browser are disabled Accessible within the class and from any class that inherits from the class that declared this member Most permissive level. Public controls have full accessibility

Private

Protected

Public

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

Practice: Creating an Inherited Form


In this practice, you will

Set the properties of the controls on the base form to prepare them for inheritance Add a new form to the project inheriting it from the base form Set the properties on the inherited form and the controls
10 min

Begin reviewing the objectives for this practice activity

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 Demonstration: 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

To set the tab order for controls

On the View menu, select Tab Order


Click a control to change its tab order Set the TabIndex property

-- OR -

Set the TabStop property to True

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

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 Set the Dock property

To dock a control

Demonstration: Organizing Controls on a Form


In this demonstration, you will see how to

Align controls on a form Layer controls on a form Anchor controls to a form

Dock controls on a form

Lesson: Creating MDI Applications


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

SDI vs. MDI Applications


SDI MDI

Only one document is visible You must close one document before you open another

Displays multiple documents at the same time Each document is displayed in its own window

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


Add a new form to the project

To create a child form

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(); }

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

Form activeChild = this.ActiveMdiChild;

To arrange child windows on the parent form

Call the LayoutMdi method

Practice: Creating an MDI Application


In this practice, you will

Create the parent form

Create the child form


Display the child form from the parent form

Begin reviewing the objectives for this practice activity

15 min

Review

Creating a Form Adding Controls to a Form Creating an Inherited Form Organizing Controls on a Form

Creating MDI Applications

Lab 1.1: Creating Windows Forms


Exercise 1: Creating a New Windows Form Exercise 2: Inheriting a New Form from an Existing Windows Form

You might also like