Beginning C# 3.0 Jack Purdum ISBN: 978-0470-26129-3 Chapter 1: Getting Started SKU: 9785CH0009874 ISBN: 978-0-470-26129-3 I Title: Beginning C# 3.
Beginning C# 3.0 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana ISBN: 978-0-470-26129-3 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data: Purdum, Jack J. (Jack Jay) Beginning C# 3.0 : an introduction to object oriented programming / Jack Purdum. p. cm. Includes index. ISBN 978-0-470-26129-3 (paper/website) 1.
1 Getting Star ted Welcome to the world of object-oriented programming and C#! The primary goal of this book is to use the C# programming language from Microsoft to teach you object-oriented programming, or OOP. This book assumes that you have no prior programming experience in any language and that you know nothing about OOP. If you do have programming experience and some familiarity with OOP, that’s fine. Having that experience makes things easier for you.
Part I: Getting Started In this chapter, you will learn about ❑ Downloading Visual Studio .NET’s C# Express ❑ Installing C# Express ❑ Testing C# Express to ensure it was installed correctly With that in mind, let’s get started. A Shor t Histor y of Object - Oriented Programming (OOP) Many people believe that OOP is a product of the 1980s and the work done by Bjarne Stroustrup in moving the C language into the object-oriented world by creating the C++ language.
Chapter 1: Getting Started Suffice it to say that C# provides you with a robust object-oriented programming language and an impressive set of tools to tackle almost any programming task. Whether you wish to develop desktop, distributed, web, or mobile applications, C# can handle the task. As you become familiar with C#, you will appreciate its relatively few keywords, its crisp syntax, and its easy-to-use development environment.
Part I: Getting Started Depending upon the speed of your Internet connection, the file should be saved on your system within a few minutes. Installing C# Express After the download completes, click the executable file that was supplied (the file was named vcssetup.exe when I installed it, but it could change). You should see a screen similar to that shown in Figure 1-2, the C# Express Edition installation screen.
Chapter 1: Getting Started Figure 1-3 Microsoft SQL Server and its associated tools are also useful, especially if you plan to do any web development in the future. Unless you have some severe disk space constraints, you should install all the components. You can always uninstall components later if you need to. Once you’ve decided on which components you wish to install, click the Next button and go fix yourself a sandwich . . . it’s going to take a while for things to get installed.
Part I: Getting Started A Test Program Using C# Express While things may appear to have been installed properly, you can’t be certain until you actually write a program and try to run it. That’s the purpose of this section of the chapter. The program is about as simple as we can make a program while remaining confident that the installation was successful. After you double-click the C# Express icon on your desktop, you should see a C# Express startup screen similar to the one shown in Figure 1-4.
Chapter 1: Getting Started Figure 1-5 Figure 1-6 In Figure 1-6 you are given a number of predefined project templates from which to choose. These templates define the types of programs that you can develop with C#. When you select one of the templates, Visual Studio creates that type of project for you as well as writing some stub code for you. 9 ISBN: 978-0-470-26129-3 I Title: Beginning C# 3.
Part I: Getting Started Stub codes are predefined pieces of code that Visual Studio writes for you as a background process. From the templates shown in Figure 1-6, select the Windows Application template. You should also type in the name you wish the program to have. I have typed in TestProgram for our example. Click OK after you’ve entered the program name you wish to use. The C# Integrated Development Environment You should now see something like Figure 1-7 on your screen.
Chapter 1: Getting Started The Major IDE Windows The IDE shown in Figure 1-7 divides the screen into three windows. The left window shows the Visual Studio Toolbox, which, by default, shows some of the objects Visual Studio makes available to you. If you look closely you can see that the Toolbox presents a smorgasbord of objects you can use in your programs, including textboxes, labels, buttons, and other controls you will find useful as you develop your programs.
Part I: Getting Started The code associated with clicking the source code icon shown in Figure 1-8 is shown in Figure 1-9. When you click the source code icon, notice that another tab is added at the top of the Source window. One tab has form1.cs (Design) on it, while the other tab has form1.cs. The first tab is for the view of the form in the design mode. (The design mode is shown in Figure 1-7.) The second tab is the source code mode and shows you the code for the program under development.
Chapter 1: Getting Started Figure 1-10 Changing the Text of a Label Object After you position the label object on the form, you can set the text for the label. One of the things that Visual Studio does automatically is size the label to be just big enough to accommodate the label’s text. Given the default font size used by Visual Studio, the default height for a label is 13 pixels. (A pixel is one dot, or point of light, on the screen of your display device.
Part I: Getting Started Figure 1-11 After you set AutoSize to False, you can resize the label object in the Source window by clicking the white sizing boxes that appear on the ends and corners of the label object. In Figure 1-12, I have increased the width of the label by clicking the middle sizing box on the right edge of the label object and dragging the edge to the right until I got the desired size. I then released the left mouse button to end up with the label object shown in Figure 1-12.
Chapter 1: Getting Started Figure 1-13 (Figure 1-13 is only large enough to show the last word typed into the Text property in the Property window. When you look at the label in the Source window, all three words appear in the label object.) By default, the text of a label object is positioned so it appears in the upper left-hand corner of the label. If AutoSize is set to True, you can’t position the text with the label object; it’s set for you automatically.
Part I: Getting Started After you have positioned the text within the label at the right place, the form should look like what is shown in Figure 1-15. Notice how the text in the label object is now centered. Figure 1-15 Running the Program This is all that you want to do at the present time to test your C# installation. If you can run the program at this point, it’s pretty certain that you have installed C# correctly. There are two simple ways to run a program. The easiest is to press the F5 key.
Chapter 1: Getting Started Summar y In this chapter you learned how object-oriented programming got its start over four decades ago. This chapter also showed you how to download and install Visual Studio’s C# Express Edition. Finally, you wrote a simple program to test the installation to make sure it was done correctly. So, now what? You could immediately proceed to the next chapter and start reading. Not a good idea.
ISBN: 978-0-470-26129-3 I Title: Beginning C# 3.
Ready for more? CHECK OUT THIS BOOK IN ITS ENTIRETY. ENTIRETY Whet Whether Whet you want to develop desktop, distributed, web, or mobile applications, C# can handle almost any programming p task. This book walks you through this robust object-oriented (OOP) programming language langu lan gu so you can quickly get started. Written by a veteran programming instructor, it provides you w with the perfect mix of tutorial and hands-on coding.