Chapter 1. Introducing Windows Forms

OBJECTIVES

This chapter covers the following Microsoft-specified objectives for the “Creating User Services” section of Exam 70-316, “Developing and Implementing Windows-Based Applications with Microsoft Visual C# .NET and Microsoft Visual Studio .NET”:

Create a Windows form by using the Windows Forms Designer:

  • Add and set properties on a Windows form.

  • Create a Windows form by using visual inheritance.

  • Build graphical interface elements by using the System.Drawing namespace.

  • Windows forms are the basic user interface element of a Windows application. The exam objectives addressed in this chapter cover the basics of designing a Windows form by using the Windows Forms Designer. This exam objective addresses the following specific topics:

    • How to create a Windows form and change its behavior and appearance through its built-in properties and through custom-added properties.

    • How to use visual inheritance to rapidly design a Windows form by inheriting it from an existing Windows form.

    • How to build various graphical interface elements by using the System.Drawing namespace.

Create, implement, and handle events.

  • Event handling is the core part of programming a user interface. This chapter describes how to make a Windows form respond to user actions. You'll find further coverage of this exam objective in Chapter 4, “Creating and Managing .NET Components and Assemblies.”

OUTLINE

Introduction 24

Key Concepts 24

An Overview of the .NET Framework 25

The Common Language Runtime 25

The Framework Class Library 26

An Overview of the Development Tools 27

The .NET Framework SDK 27

Visual Studio .NET 28

Understanding Classes, Inheritance, and Namespaces 29

Classes 29

Inheritance 31

Namespaces 31

Creating a Windows Forms Application 32

Using the System.Windows.Forms.Form Class 33

Designing a Windows Form by Using the Windows Forms Designer 34

Exploring the Generated Code 37

Running a Windows Form 40

Using the Application Class 42

Using the MessageBox Class 46

Setting and Adding Properties to a Windows Form Windows Form 48

Using the Visual Designer to Set Windows Form Properties 48

Setting Windows Form Properties Programmatically 51

Adding New Properties to a Windows Form 57

Using Visual Inheritance 61

Event Handling 64

Handling Events by Attaching a Delegate 65

Handling Events by Overriding a Protected Method of a Base Class 71

Building Graphical Interface Elements by Using the System.Drawing Namespace by Using the System.Drawing Namespace 76

Understanding the Graphics Objects 77

Understanding the Windows Forms Coordinate System 78

Drawing Text on a Form 79

Drawing Shapes 85

Working with Images 94

Chapter Summary 101

Apply Your Knowledge 102

STUDY STRATEGIES

  • Make yourself comfortable with the major properties of Windows forms. This chapter's examples and exercises introduce the most important form properties.

  • Invest time looking at and understanding the code that is automatically generated by Visual Studio .NET for you.

  • Make sure you fully understand event handling. This will enable you to write interactive Windows applications.

  • Experiment with classes in the System.Drawing namespace. In addition to the completing the examples and exercises in this chapter, it would be a good idea for you to create a small sample program to test the behavior of a class or a property whenever you are in doubt.

  • If you are new to object-oriented programming, consider reading all or some of the recommended material listed in the “Suggested Readings and Resources” section at the end of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.123.252