Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment
Visual Studio.NET • A development “shell” for creating applications • Visual designer • Context editor with Intellisense for typing code • Programming language compilers • Run/Debug environment
Visual Studio.NET and the IDE • Any C# application can be written with a simple text editor (such as Notepad) as long as the Framework Class Libraries (FCL) are present (as we saw in FormFromTextFile). • Normally, however, it is much simpler to program and manage C# applications using the Visual Studio Integrated Development Environment (IDE). FormFromIDE
Starting Visual Studio.NET • Start Visual Studio.NET from a Desktop shortcut. -or- • , Programs:
Adjust the View in the IDE • To undock a docked window so it floats on the screen, drag it by its title bar away from the edge of the application window or double-click its title bar. Double-click a window’s title bar to return the window to its default location. • To hide a docked window, click its Auto Hide button. The window will be displayed as a tab at the edge of the screen. You can redisplay it by placing the mouse pointer over the tab. • To return all windows to their original Visual Studio positions, choose Window, Reset Window Layout in the menu.
Setting Default Location for Projects • Choose Tools, Options in the menu. • Click the + in front of Projects and Solutions. • Click General under Projects and Solutions. • Click the Browse button next to Visual Studio projects location: and choose the folder you created for this course.
Visual Studio Solutions • A solution is comparable to a workspace in C++ V6. • The first project created in the solution gives its name to the solution and thus to the namespace as well. • At times, it may be advisable to change the name of either the project or the namespace.
The Designer View • The IDE displays a design-time view of the visible portion, if any, of the object being designed. • A Designer view of a formobject appears by default in a new project. • The form will be a window at run time.
The Code View • The IDE provides an editor for building the actual code for the class or classes that make up your new project. • Pre-existing (library) code is not visible here. • Choose View Codeicon in Solution Explorer or click Code tab in Designer Window.
Adjusting Properties at Design Time • The IDE provides a convenient window for assigning values to object properties at design time. • The Properties Window displays all available properties for any object that is selected within the IDE. • Use F4 or View,Properties Window from menu, if the Properties Window is not visible.
Some Form Properties • A number of form properties can be changed at design time. • Dimensions of the form can be adjusted by dragging the selection handles or by assigning values to the Size Property in the property window. • The run time screen position of the window can be adjusted by choosing values for the StartPosition property.
More Form Properties • Every form should have a Text property that reflects the role of the form in the project; the text typed as the Text Property appears in the Titlebar of the window. • The form icon can also be changed by assigning a new icon file to the Icon property; later, we will learn how to create a custom icon. FormWithChangedProperties
Compiling and Running • Choose Build, Build Solution from menu to compile without running. • 3 ways to run (and build, if necessary) an application: • Choose Debug, Start Debugging from menu • Press F5 • Click the Debug tool in the toolbar
The Window Control Box • When the Windows Application project runs, the form appears as a Window object. • The project remains running until the window is closed. • The window can be closed by clicking the in the Control Box in the Titlebar.
The Window Control Box • The Control Box also contains icons for minimizing the window to a taskbar item and maximizing the window to full screen size. • The Maximize icon becomes a Restore Down icon if the window is maximized. • All, some, or none of these icons may be displayed by setting the ControlBox, MinimizeBox, and/or MaximizeBox properties to true or false. Maximize Minimize Restore Down Close ControlBox
Show in TaskBar • You may not wish to have a Taskbar item appear to represent your window. • Setting the Show in TaskBar property to False at design time will accomplish this.
Let’s Review C++ File Structure • Before looking at the C#.NET V2005 file structure of the project we just created, we’ll review how C++ V6 and .NET versions of projects look in My Computer.
Debug or Release HW777 File Structure of a C++V6 or .NETConsole Application HW777.exe * HW777.dsw or (.sln) source.obj * source.cpp HW777.pdb HW777.ncb HW777.pch * HW777.dsp HW777.ilk HW777.plg vc60.pdb HW777.opt vc60.idb * Note: Debug folder contains all 7 subfiles.Release folder only contains 4 asterisked subfiles.
Let’s Review C# V2003 File Structure • Before looking at the C#.NET V2005 file structure of the project we just created, we’ll review how C#.NET V2003 projects look in My Computer.
HW888 bin obj Debug File Structureof a C#.NETV2003Windows Application HW888.exe HW888.pdb HW888.sln frmDiner.cs App.ico HW888.csproj AssemblyInfo.cs HW888.csproj.user frmDiner.resx HW888.suo
Structure of a C# Solution • The IDE creates a collection of files called a solution. • Normally, a solution contains one project. • A project generates an application. • Multiple projects may be contained within one solution.
Let’s Look at C# V2005 File Structure • Now we’ll look at how the C#.NET V2005 project we just created looks in My Computer.
HW999 bin obj Properties Debug HW999 File Structure of a C#.NET V2005 Windows Application HW999.exe frmDeesDiner.cs frmDeesDiner.Designer.cs HW999.csproj HW999.sln frmDeesDIner.resx HW999.suo Program.cs
Important Files • The project file (with an extension of .csproj) keeps track of the files that make up the project and records various settings for the project. • The solution file (with an extension of .sln) keeps track of the projects that make up the solution. • When you open a project file, Visual Studio opens the solution that contains the project. And when you open a solution file, Visual Studio automatically opens all the projects contained in the solution.
Form Files • In C# 2005, each form is defined by two C# files. Each file contains a partial class. The file with the .cs extension contains the code that is entered by the programmer; the file with the Designer.cs extension contains the code that is generated when the programmer works with the Form Designer. When the project is compiled, these two partial classes are combined into a single class that determines the appearance and operation of the form.
Other Files • A source code file that doesn’t define a form is usually stored in a single C# source file that contains a single class. • The References folder contains references to the assemblies for the namespaces that the application can use. These namespaces contain the classes that the project requires. In most cases, all the references that you need are included when the project is created.
Opening a C#.NET V2005 Project from My Computer • To open a project from My Computer, double-click the solution file (ex. Homework999.sln). • The solution file (ex. Homework999.sln), which is a file that contains pointers to all Projects within a Solution, is now stored outside of the Project folder.
E-mailing Assignments to Professor • When e-mailing an assignment to me, you must submit the circled folder and all of its contents. You should “zip” this folder into 1 file for easy transmission using a program named WinZip. If you don’t have WinZip, download it from downloads.com .
“Zipping” a Folder via WinZip • Navigate to folder in My Computer. • Right-click and choose WinZip from context menu. • Choose 2nd option, Add to Homework999.zip . • One file, Homework999.zip, containing the contents of entire Homework999 folder, is created.
Start a New E-mail Message • Start http://mail.strose.edu and click New message. Add professor e-mail address in To: area and assignment number in Subject: area.
Adding .zip File as an Attachment • Click in message toolbar. You will see the Attachments dialog. • Browse for your .zip file.
Adding .zip File as an Attachment • After the file name displays in Choose a file to attach box, click the Attach button. • The .zip file will then show as a Current File Attachment. Click the Close button.
Send E-mail Message • Your e-mail message should now display the attached .zip file. • Send the e-mail message.
Events Application Lifetime and Object Responses to Stimuli
Event-Driven Applications • Objects can both send, and react to, special messages or stimuli called events. • By and large, event-driven applications run until they are stopped by user intervention. • Event driven applications respond to any events that they detect.
Reacting to a Click Event • An object can react to the event caused by clicking the mouse. • Objects react to events by executing code within a special method (function) called an event handler. • A specific event (clicking this object) causes the function to run. • Any instructions coded within the function are then executed. FirstEvent
Associating Handlers with Events • An event handler is a method (function) that contains the code that will be executed when a particular event occurs for the a specific object. • Event handlers may be associated with objects and their events in several ways: • The default handler for a control (often the Click event handler) will be added automatically to the code area, when you double-click the control in the Designer View. • Or, you may double-click a particular event in the Properties Window.
Associating Events via the Property Window • A list of all available events for an object is available in the Properties window if the is toggled. • Double-click the appropriate event. • Selecting an event here causes an event handler skeleton to be created in the code area.
A New Handler Function • Event Handler functions are named with a combination of the object and the event.
“Event Wiring” • A separate line of code is automatically written (in the Windows Generated Coderegion of the formName.Designer.cs file) to connect the event handler to the event. You can think of this as “event wiring” or “automatic registration” of the event handler function.