Sams Teach Yourself C# in 24 Hours
- Table of Contents
- Copyright
- About the Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- Audience and Organization
- Conventions Used in This Book
- Onward and Upward!
- Part I. The Visual Studio Environment
- Hour 1. A C# Programming Tour
- Hour 2. Navigating C#
- Hour 3. Understanding Objects and Collections
- Hour 4. Understanding Events
- Part II. Building a User Interface
- Hour 5. Building FormsPart I
- Hour 6. Building FormsPart II
- Hour 7. Working with the Traditional Controls
- Hour 8. Advanced Controls
- Hour 9. Adding Menus and Toolbars to Forms
- Hour 10. Drawing and Printing
- Part III. Making Things HappenProgramming!
- Hour 11. Creating and Calling Methods
- Hour 12. Using Constants, Data Types, Variables, and Arrays
- Hour 13. Performing Arithmetic, String Manipulation, and Date/Time Adjustments
- Hour 14. Making Decisions in C# Code
- Hour 15. Looping for Efficiency
- Hour 16. Debugging Your Code
- Hour 17. Designing Objects Using Classes
- Hour 18. Interacting with Users
- Part IV. Working with Data
- Hour 19. Performing File Operations
- Hour 20. Controlling Other Applications Using Automation
- Hour 21. Working with a Database
- Part V. Deploying Solutions and Beyond
- Hour 22. Deploying a Solution
- Hour 23. Introduction to Web Development
- Hour 24. The 10,000-Foot View
- Appendix A. Answers to Quizzes/Exercises
Hour 5. Building Forms—Part I
With few exceptions, forms are the cornerstone of every Windows application's interface. Forms are essentially windows and the two terms are often used interchangeably. More accurately, "window" refers to what's seen by the user and what the user interacts with, whereas "form" refers to what you see when you design. Forms let users view and enter information in a program (such as the form you built in your Picture Viewer program in Hour 1, "A C# Programming Tour"). Such information may be text, pictures, graphs—almost anything that can be viewed onscreen. Understanding how to design forms correctly will enable you to begin creating solid interface foundations for your programs.
Think of a form as a canvas on which you build your program's interface. On this canvas, you can print text, draw shapes, and place controls with which users can interact. The wonderful thing about C# forms is that they behave like a dynamic canvas; not only can you adjust the appearance of a form by manipulating what's on it, you can also manipulate specific properties of the form itself.
In previous hours, you manipulated the following form appearance properties:
- Text
- Height
- Left
- Top
- Width
The capability to tailor your forms, however, goes far beyond these simple manipulations.
There is so much to cover about Windows Forms that I've broken the material into two hours. In this hour, you'll learn the very basics of forms—adding them to a project, manipulating their properties, and showing and hiding them using C# code. Although you've done some of these things in previous hours, here you'll learn the nuts and bolts of the tasks you've performed. In the following hour, you'll learn more advanced form techniques.
The highlights of this hour include the following:
- Changing the name of a form
- Changing the appearance of a form
- Displaying text on a form's title bar
- Adding an image to a form's background
- Giving a form an icon
- Preventing a form from appearing in the taskbar
- Specifying the initial display position of a form
- Displaying a form in a normal, maximized, or minimized state
- Changing the mouse pointer
- Showing and hiding forms
Changing the Name of a Form | Next Section

Account Sign In
View your cart