Class2.DOC

(3837 KB) Pobierz
Beginning Visual C# Express

2-13



The Visual C# Express Environment

 

Beginning Visual C# Express

 

 

2. The Visual C# Express Design Environment

 

 

Review and Preview

 

              In Class 1, we learned the important parts of a Visual C# Express project.  We saw that a project is built on a form using controls (also called objects).  By interacting with the controls using events, we get the computer to do assigned tasks via instructions we provide.  In this second class, we will learn the beginning steps of building our own Visual C# Express projects by looking at the different parts of the project and where they fit in the Visual C# Express design environment.  Like Class 1, there are also a lot of new terms and skills to learn.

 

 


Parts of a Visual C# Express Project

 

              In Class 1, we saw that there are four major components in a Visual C# Express application:  the solution, the project, the form, and the controls.  A solution can contain multiple projects.  In this course, solutions will only contain a single project, so the words solution and project are used interchangeably.   Project is the word used to encompass everything in a Visual C# Express project.  Other words used to describe a project are application or program.  The form is the window where you create the interface between the user and the computerControls are graphical features or tools that are placed on forms to allow user interaction (text boxes, labels, scroll bars, command buttons).  Recall the form itself is a control.  Controls are also referred to as objects.  Pictorially, a project is:

 

 

 

 

 

 

 

 

 

Control

Project



Control

Form

Control

Control



Control

 

 

 

 

So, in simplest terms, a project consists of a form containing several (and some projects contain hundreds) controls. 

 


Every characteristic of a control (including the form itself) is specified by a property.  Example control properties include names, any text on the control, width, height, colors, position on the form, and contents.  Properties are used to give your project the desired appearance.  For each control studied in this class, we will spend a lot of time talking about properties.

 

In Class 1, we saw that by interacting with the controls in the Sample project (clicking buttons, choosing different options, typing text), we could make things happen in our project by generating control events.  We say that Visual C# Express is an event-driven language and it is governed by an event processor.  That means that nothing happens in a Visual C# Express project until some event occurs.  Once an event  is detected, the project finds a series of instructions related to that event, called an event method.  That method is executed, then program control is returned to the event processor:

 

Event processor



Event?











 

Event

Method

Event

Method

Event

Method

Event

Method

 

 

Event methods associated with various controls are where we do the actual computer programming.  These methods are where we write C# language statements.  You will learn a lot of programming and C# language in this class. 

 


              In summary, the major parts of a Visual C# Express project are:

 

·         form

·         controls

·         control properties

·         control event methods

 

Now, let’s take a look at the Visual C# Express programming environment and identify where we can access each of these project components.


Parts of the Visual C# Express Environment

 

              Visual C# Express is more than just a computer language.  It is a project building environment.  Within this one environment, we can begin and build our project, run and test our project, eliminate errors (if any) in our project, and save our project for future use.  With other computer languages, many times you need a separate text editor to write your program, something called a compiler to create the program, and then a different area to test your program.  Visual C# Express integrates each step of the project building process into one environment.  Let’s look at the parts of the Visual C# Express environment.  To help in this look, we first need to get a new project started.  We won’t do anything with this project.  We just use it to identify parts of the Visual C# Express environment.

 


Starting a New Visual C# Express Project

 

Every time you want to build a project using Visual C# Express, a first step is to create a new project.  Start Visual C# Express using the procedure learned in Class 1.  We will start a new project using the toolbar under the Visual C# Express menu.  Look for this button (the first button on the left):

 

New Project Toolbar Button



 

You can also start a new project by selecting File from the menu, then clicking New Project.

 

Click the New Project button and a New Project box appears:

 

 

We will always be building windows applications, so under Visual Studio installed templates, select Windows ApplicationChoose a Name for your project – I used FirstTryOnce done, click OKYour new project will appear in the Visual C# Express environment, displaying several windows.

 


Main Window

 

The Main Window is used to control most aspects of the Visual C# Express project building and running process:

 

 

The main window consists of the title bar, menu bar, and toolbars.  The title bar indicates the project name (here, FirstTry)The menu bar has drop-down menus from which you control the operation of the Visual C# Express environment.  The toolbars have buttons that provide shortcuts to some of the menu options.  You should be able to identify the New Project button.  Also, look for the button we used in Class 1 to start a project.

 


Solution Explorer Window

 

              The Solution Explorer Window shows which files make up your project:

 

 

If the Solution Explorer window is not present on the screen, click View on the main menu, then Solution Explorer.  As an alternate, if the window does not show up, press the R key while holding down <Ctrl>.  If you select the form file (Form1.cs), you can obtain a view of the project form by clicking the View Designer button at the top of the window.  Or, you see the actual C# coding within a form by clicking the View Code button.  We will look at this code window soon.

 


Design Window

 

              The Design Window is central to developing Visual C# Express applications.  It is where you build your form and write actual code.  You should see a blank form in this window:

 

 

If the form is not present on the screen, select Form1.cs in the Solution Explorer window.  Then, click View on the main menu, then Designer.  Or, press the <F7> function key while holding down <Shift>.

 


Toolbox Window

 

              The Toolbox Window is the selection menu for controls used in your application.  Many times, controls are also referred to as objects or  tools.  So, three words are used to describe controls:  objects, tools, and, most commonly, controls.

 

 

If the toolbox window is not present on the screen, click View on the main menu, then ToolboxMake sure you are viewing the All Windows Forms controls.  See if you can identify some of the controls we used in Class 1 with our Sample project.

 


Properties Window

 

              The Properties Window is used to establish initial property values for controls.  It is also used to establish control events (we will see how in Class 3) – for now, we just look at the properties – to do this make sure the Properties toolbar button (in the properties window) is selected and not the Events button (see the picture below):

 

 

Click here to see Events



Click here to see Properties



 


The drop-down box at the top of the window lists all controls on the current form.  Under this box are the available properties for the currently selected object (the Form in this case).  Different views of the properties are selected using the toolbar near the top of the window.  Two views are available:  Alphabetic and Categorized.  We will always used the Alphabetic view.

Drop-down

list box



Click here for

Alphabetic view



 

If the properties window is not present on the screen, c...

Zgłoś jeśli naruszono regulamin