Class1.doc

(1184 KB) Pobierz
Beginning Visual C# Express

1-21



Introducing Visual C# Express

 

Beginning Visual C# Express

 

 

1. Introducing Visual C# Express

 

 

A Brief History of Visual C# Express

 

              In the mid-1960’s, most computing was done on large computers taking up entire floors of buildings (these machines had less computational power than the laptop I’m typing these notes on!).  Most programming was done in cryptic languages by engineers and mathematicians.  Two professors at Dartmouth College wanted to explain programming to “normal” people and developed the BASIC (Beginner’s All-Purpose Symbolic Code) language to help in that endeavor.  BASIC was meant to be a simple language with just a few keywords to allow a little math and a little printing.

 

              In the later 1960’s, timeshare computing, where a user could sit at a terminal and interact with the computer, became popular.  The primary language used in these interactive sessions was BASIC.  The Dartmouth BASIC was not sufficient for the many applications being developed, so many extensions and improvements were made in the BASIC language.  Many of the first computer games were written on timeshare terminals using BASIC – gambling games, world simulations and the classic Star Trek game were very popular.

 


              In the mid-1970’s, an issue of Popular Science magazine changed the world of computers forever.  On the cover was an Altair computer.  About all the computer could do was flash some lights according to a program written by the user.  But, it was the first home computer.  Two young guys in Seattle, Bill Gates and Paul Allen, saw the potential.  They developed a BASIC language for the Altair computer and marketed it through their new company – Microsoft.  It sold for $350 and was distributed on a cassette tape.

 

              Since those early days, the folks at Microsoft have developed many other products and many other programming languages.  The product you will learn in this set of notes is called Visual C# Express.  The word Visual means you will build Windows-based applications that a user can see and interact with.  The term C# (pronounced “cee sharp”) refers to the particular language used within the Visual C# Express environment.  This language was developed using pieces of other languages called C, C++ and Java.  And, the term Express is used to indicate this is a special version of another Microsoft product called Visual C# .NET.  The Express version has been developed for beginners like yourself (providing you with a “speedy” way to learn programming).  Visual C# Express is one of the easiest programming languages to learn.  Yet, even though it is easy to learn and to use, Visual C# Express can also be used to develop very powerful computer programs.  Visual C# Express provides a sophisticated environment for building and testing Windows-based (Windows 2000, Windows XP or Windows NT) applications.  You’ve used Windows-based applications before.  Microsoft’s programs like Word, Excel, Internet Explorer and the windows that appear within these applications (to open and save files, to print files) are all Windows-based applications.  These applications are not written in Visual C# Express (they are written in a language called C++), but they do demonstrate the functionality you can put in your Visual C# Express applications.

 


Visual C# Express can be used to write computer games, businesses can use Visual C# Express to manage their databases, webmasters can use Visual C# Express to develop web pages, and people like yourself can use Visual C# Express to build Windows applications they want and need in their everyday home and work life.  In these notes, you will learn how to use Microsoft’s Visual C# Express to write your own Windows-based applications.  You may not become a billionaire like Bill and Paul, but hopefully you’ll have some fun learning a very valuable skill.


Let’s Get Started

 

              Learning how to use Visual C# Express to write a computer program (like learning anything new) involves many steps, many new terms, and many new skills.  We will take it slow, describing each step, term, and skill in detail.  Before starting, we assume you know how to do a few things:

 

·         You should know how to start your computer and use the mouse.

·         You should have a little knowledge on working with your operating system (Windows 2000, XP, or NT).

·         You should know how to resize and move windows around on the screen.

·         You should know how to run an application on your computer by using the Start Menu.

·         You should know how to fill in information in Windows that may pop up on the screen.

·         You should know about folders and files and how to find them on your computer.

·         You should know what file extensions are and how to identify them.  For example, in a file named Example.ext, the three letters ext are called the extension.

·         You should know how to click on links to read documents and move from page to page in such documents.  You do this all the time when you use the Internet.

 


You have probably used all of these skills if you’ve ever used a word processor, spreadsheet, or any other software on your computer.  If you think you lack any of these skills, ask someone for help.  They should be able to show you how to do them in just a few minutes.  Actually, any time you feel stuck while trying to learn this material, never be afraid to ask someone for help.  We were all beginners at one time and people really like helping you learn. 

 

              Let’s get going.  And, as we said, we’re going to take it slow.  In this first class, we will learn how to get Visual C# Express started on a computer, how to load a program (or project) into Visual C# Express, how to run the program, how to stop the program, and how to exit from Visual C# Express.  It will be a good introduction to the many new things we will learn in the classes to come.

 


Starting Visual C# Express

 

              We assume you have Visual C# Express installed and operational on your computer.  If you don’t, you need to do this first.  Again, this might be a good place to ask for someone’s help if you need it.  At this writing, the Beta 2’ version is available for free download from Microsoft.  Follow this link for complete instructions for downloading and installing Visual C# Express on your computer:

 

http://lab.msdn.microsoft.com/express/vcsharp/default.aspx

 

You should download and install both Visual C# Express and the MSDN Library (has all the help files).  Please note these are very large files.  If you don’t want to download the files, the website above also has instructions for obtaining a CD copy at a nominal cost.

 

              Once installed, to start Visual C# Express:

 

·         Click on the Start button on the Windows task bar.

·         Select Programs, then Visual C# 2005 Express Edition

 

(Some of the headings given here may differ slightly on your computer, but you should have no trouble finding the correct ones.)  The Visual C# Express program should start.  Several windows will appear on the screen, with the layout depending on settings within your product.

 


Upon starting, my screen shows:

Toolbar

Main Menu

Title Bar

Main Window













Welcome Page

Design Window

 

 

 

              This screen displays the Visual C# Express Integrated Development Environment (IDE).  This is where we build, run and work with our applications.  Let’s point out just a few items on the screen. There are many windows on the screen.  At the top of the screen is the Visual C# Express Main Window.  At the top of the main window is the Title Bar.  The title bar gives us information about what program we’re using and what Visual C# Express program we are working with.  Below the title bar is the Main Menu from where we can control the Visual C# Express program.  You should be familiar with how menus work from using other programs like word processors and games.  Under the main menu is a Toolbar.  Here, little buttons with pictures also allow us to control Visual C# Express, much like the main menu.  If you put the mouse cursor over one of these buttons for a second or so, a little ‘tooltip’ will pop up and tell you what that particular button does - try it!  Almost all Windows applications (spreadsheets, word processors, games) have toolbars that help us do different tasks.  This is the purpose of the Visual C# Express toolbar.  It will help us do most of our tasks.  In the middle of the screen is the Welcome Page, contained in the Design WindowThis page has many helpful topics you might be interested in pursuing as you learn more about Visual C# Express. – especially note the topics under Getting Started.

 

At any time, your particular screen may look different than ours.  The Visual C# Express environment can be customized to an infinite number of possibilities.  This means you can make things look anyway you want them to.  You can ‘dock’ windows or ‘float’ windows.  You can move windows wherever you want or you can completely delete windows.  And, different windows will appear at different times.  As you become more experienced with Visual C# Express, you will learn ways you want things to be.  We encourage you to try different things.  Try moving windows.  Try docking and floating.  We won’t talk a lot about how to customize the development environment.  (We will, however, always show you how to find the particular window you need.)  Visual C# Express offers help on how to customize.  In the lower right corner of our screen is a window entitled Dynamic Help (if you don’t see this window, click the Help menu item and select Dynamic Help).  There are several ‘clickable’ topics there that discuss how to ‘configure’ the Visual C# Express environment to you liking.  Of particular interest are Customizing the Development Environment and Visual Studio Walkthroughs.

 


Opening a Visual C# Express Project

 

What we want to do right now is open a project.  Windows applications written using Visual C# Express are referred to as solutions.  A solution is made up of one or more projects.  Projects include all the information we need for our computer program.  In this course, our applications (solutions) will be made up of a single project.  Because of this, we will use the terms application, solution and project interchangeably.  Included with these notes are many Visual C# Express projects you can open and use.  Let’s open one now. 

 

We will open a project using the main menu.  Follow these steps:

 

·         Select File from the main menu, then click Open, then select Project/SolutionAn Open Project window will appear:

 

 

·        
Find the folder named BeginVCSE (stands for Beginning Visual C# (Sharp) Express).  This is the folder that holds the notes and projects for this course.  Open that folder.

·         Find and open the folder named BVCSE Projects.  This folder holds all the projects for the course

 

Remember how you got to this folder.  Throughout the course, you will go to this folder to open projects you will need.  Open the project folder named Sample.

 

              In this project folder, among other things is a Visual Studio Solution file named Sample (with sln extension) and a Visual C# Express Project file named Sample (with csproj extension).  Open the Sample solution file (as shown in the example Open Project window).  Since there is only one project in this solution, you could also open the project file and get the same results, but it is better to always open the solution file. 

 


Once the project is opened, many windows are now on the screen:

 

 

Look for the Solution Explorer window (if it is not there, choose View in the menu and select Solution Explorer).  This lists the files in our solution.  Right-click the file Form1.cs and choose Open


In the Design window will appear a window that looks something like this:

 

 

This is our project named Sample.  We’re going to spend a bit of time explaining everything that is displayed here.  This will introduce you to some of the words, or vocabulary, we use in Visual C# Express.  There are lots of terms used in Visual C# Express.  Don’t try to memorize everything - you’ll see these new words many times through the course.

 

              We call the displayed project window a Form.  All Visual C# Express projects or programs are built using forms.  In fact, you have probably noticed that all Windows applications are built using forms of some type.  At the top of the form is the Title Bar.  It has an icon (little picture) related to the form, a description of what the form does (Beginning Visual C# Express - Sample), and three smaller buttons that control form appearance (we won’t worry about these buttons right now).  There are lots of other things on the form.  These other things are the ‘heart’ of a Visual C# Express computer program. 

 

              You see a set of square buttons with toy names next to them.  You see pictures of toys.  You see a set of round buttons with color names next to them.  There is a little box you can type in with something called a scroll bar on the right side.  There’s a big button that says Beep!  There’s a little device for picking the value of a number.  And, there’s a ball in a big rectangle with a button that says Start and, below the form, a little thing that looks like a stopwatch.  We call all of these other things on the form Controls or Objects.  Controls provide an interface, or line of communication, between you (or the user of your program) and the computer.  You use the controls to tell the computer certain things.  The ...

Zgłoś jeśli naruszono regulamin