1 / 44

Creating Projects using Microsoft Visual Studio 2010

Creating Projects using Microsoft Visual Studio 2010. CTEC1239/2012W Computer Programming. Visual C# (and Visual Basic). The environment is still Windows , but the compiled code runs on the .Net Common Language Runtime (CLR) environment (like Java apps run on the JRE).

conroy
Télécharger la présentation

Creating Projects using Microsoft Visual Studio 2010

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating Projects using Microsoft Visual Studio 2010 CTEC1239/2012W Computer Programming

  2. Visual C#(and Visual Basic) • The environment is still Windows, but the compiled code runs on the .NetCommon Language Runtime (CLR) environment (like Java apps run on the JRE).

  3. Visual Studio 2010 • Start at the File menu ...

  4. File | New | Project… [Ctrl-Shift-N] • The “New Project” dialog box appears

  5. Choose the Language, Environment, and Project Type • The project types are: Console Application (text) and Windows Forms Application (GUI).

  6. Choose the Project Location • Click on to pop up the “Project Location” dialog box. From here, choose or create a folder in which to store your projects. • Each project will have its own subfolder.

  7. Give the Project a Name • The name will be used for both the project subfolder and the executable. • For example, for a C++ Win32 Console app, the project folder will be C:\tmp\Test and the executable will be written to C:\tmp\Test\Debug\Test.exe

  8. Creating a C# Console Application

  9. C# Console Apps • Choose the language (Visual C#), environment (Windows), project type (Console Application). • Follow the usual procedure... project location and project name.

  10. C# Console App Project

  11. C# Console App Project(2) • The C# using keyword includes .Net libraries. • The C# namespace keyword is used because .Net classes are organized in assemblies. • Your project is an assembly.

  12. C# Console App Project(3) • Like Java, each C# program must have consist of at least one class. • The program entry point is “main”, but C# capitalizes the name to Main(so does VB). • The fully-qualified name of the class in this example is VCSConsoleTest.Program

  13. C# Console App Files • Don’t mess with the Properties folder! • The bin and obj folders are used for building (they can be safely deleted). • Don’t forget the secret hidden .suo file.

  14. Contrived C# Console Program Example - Code

  15. Cleaning C# Projects • Close the project in Visual Studio. • Copy the .exe file from bin\Debug if necessary. • Remove the bin and obj folders. • Delete the secret hidden .suofile.

  16. CREATING A VISUAL C# WINDOWS FORMS APPLICATION

  17. C# GUI Apps • Choose the language (Visual C#), environment (Windows), project type (Windows Forms Application). • Choose the location. • Name the project (overwriting the name suggested by Visual Studio). • Design the form and write the underlying code. • Build the project.

  18. C# GUI App in Visual Studio

  19. C# GUI App Files When you start designing, a Form1.resx file will be created by Visual Studio. Do not mess with this file!

  20. C# GUI Projects • Follow the same steps as for VB GUI projects ... (refer to previous slides)

  21. C# Project Example • As an example, consider a digital clock application...

  22. C# Project Example (2) • First, create the project and set the form title.

  23. C# Project Example (3) • From the Toolbox, as a MenuStrip control

  24. C# Project Example (4) • Fill in the menu items.

  25. C# Project Example (5) • Create an event by selecting a menu item and clicking on the (lightning bolt) icon.

  26. C# Project Example (6) • Create an event by selecting a menu item and clicking on the (lightning bolt) icon and selecting the Click event. • You can also double click on the menu item.

  27. C# Project Example (7) • The empty method is created by Visual Studio.

  28. C# Project Example (8) • Write the code for the menu item.

  29. C# Project Example (9) • To end the program, close the form by calling the Close() method (if the user clicks the Yes pushbutton.)

  30. C# Project Example (10) • To add the “Clock Settings” dialog box: • Choose Project | Add Windows Form... to add a new form to the project. • Change the Name and Text (caption) properties of the form.

  31. C# Project Example (11) • Set certain properties to make the new form behave like a dialog box.

  32. C# Project Example (12) MaximizeBox = False MinimizeBox = False ShowInTaskbar = False TopMost = True

  33. C# Project Example (13) New name of Form2 class Main form is parent window Method to show form as a modal dialog box

  34. C# Project Example (14) • To add the “About” box, go to Project | Add new item and choose AboutBox

  35. C# Project Example (15) • Fill in the Text property for the about box and for each label.

  36. C# Project Example (16) • Write the code (in Form1.cs) to pop up the About box.

  37. C# Project Example (17) WHAT HAPPENED???

  38. C# Project Example (18) • Look at code in AboutBox1.cs: Properties in AboutBox1.Designer.cs are replaced by values from AssemblyInfo.cs

  39. C# Project Example (19) • Look at code in AssemblyInfo.cs:

  40. C# Project Example (20) The “Quick & Dirty” SolutionTM • comment out code in AboutBox1.cs:

  41. C# Project Example (21)

  42. C# Project Example (22) A Better Way... • copy the labels to AssemblyInfo.cs:

  43. C# Project Example (23)

  44. C# Project Example: WHAT’S NEXT? • Complete the “Clock Settings” dialog box (controls) • Store the clock settings in variables • Write the code to handle the dialog box (i.e., user input validation) • Add the bitmaps • Add the synchronized thread

More Related