480 likes | 635 Views
Computer Science 140 C# Programming. Introduction to CS 140 Introducing .NET and Visual Studio.NET. Today's Plan. Go over the syllabus Cover .NET Basics Just what is a "platform"? Evolution of platform architecture Windows and .NET architecture Building a .NET application
E N D
Computer Science 140C# Programming Introduction to CS 140Introducing .NET and Visual Studio.NET
Today's Plan • Go over the syllabus • Cover .NET Basics • Just what is a "platform"? • Evolution of platform architecture • Windows and .NET architecture • Building a .NET application • A quick intro to using Visual Studio .NET • In-class Exercise 1
Syllabus I • Class Web Site • csjava.occ.cccd.edu/~gilberts/CS140F02 • Meeting • Class is in Computing Center 102 • 3.5 hours lecture, 1.5 hours lab • Lecture from 7:15 - 8:45 p.m. • Lab from 9:00 - 9:50 p.m.
Syllabus II • Instructor • Stephen Gilbert • Preferred communication, email: • StephenGilbert@netscape.net, sgilbert@occ.cccd.edu • Phone: (714) 432-0202 ext 21173 • In person office hours: • Monday 6-7, Wednesday 3-4 • Tuesday/Thursday 1:30-2:30
Syllabus III • Course description • Is this course for you? • Goals & Outcomes • Course requirements • Reading & workload • Exams • Quizzes • In-class programming assignment • Programming assignments • Grades
Syllabus IV • Course resources • Textbook • Deitel & Deitel, C#, How to Program, 1st ed. • Software • Operating system: NT, 2000, XP (Pro) • Visual Studio .NET (aka VS7) • The .NET framework • Class Schedule
Syllabus V • Class policies • Late work • Absences • Academic honesty • Disruptive behavior • Disabilities • Changes to the syllabus
Computing Platforms I • The most basic "platform" is the hardware • Memory • A CPU (fetch,decode,execute,store) • Input and output devices • Secondary storage and other peripherals • Suppose we have a particular hardware platform • How do we display output and read input? • Store files on disk? • Load and start programs running? • We need some minimal software : BIOS (firmware)
Computing Platforms II • BIOS provides minimal platform to develop software • Interface to BIOS is machine language • Ability to print to screen, send data to ports • Read/write disks by accessing controller ports • Really need "control program" to sit on top of BIOS • This is the role of the operating system • Provides protocol for input and output (command-line) • Provides scheduling/submission to CPU • Provides abstraction layer on top of peripheral devices
Applications Operating System Hardware / BIOS Computing Platforms III • Operating system provides basis for first "real" platform: Traditional Computing Architecture
Computing Platforms IV • Let's use MS DOS as example of traditional platform • Application layer includes system software (languages) • Sometimes application layer went through O/S • You write: ch = getchar(); // read a char in C • C runtime looks for available char (internally buffered) • None available? Calls operating system to read a "block" • Sometime application layer went around O/S • You write: putchar('A'); • Most MS-DOS compilers ignore BIOS/OS, write to HW
Computing Platforms V • Problems with MS-DOS (traditional) architecture • Problems for the user • Command line is hard to learn • Programs tied to the hardware • Programs don't work together • The Programmer's Problems • Variety of different hardware (printers, etc.) to support • Excessive UI code to write (60-70%) • No "UI" abstraction equivalent to file system abstraction
The Windows Platform • Designed to solve problems with traditional platform • Common User Interface • Familiarity for the user • Availability for the programmer • Queued Input Model • Cooperation between programs • Sharing of hardware devices • Device Independence • Multitasking • Interprocess Communication
Application O/S Win GDI Device Hardware Windows Architecture • Device Layer • System Layer • OS • Input • Interface • Output
Windows Architecture II • OS Components • Contained in KERNELXXX.DLL/EXE • Memory manager • Dynamic loading, linking, scheduling • Input Components • Device-driver layer • The Hardware [System] Queue • Hardware interrupts • Timers, keyboard, mouse
Windows Architecture III • User Interface Components [USERXXX.DLL/EXE] • Windows • Window classes, instance, & child windows • Menus & dialogs • Output Components - GDI [GDIXXX.DLL/EXE] • Graphics Device Interface • The Device Context • Coordinate transformation • Drawing primitives • Device drivers
Writing Windows Programs • Application Programming Interfaces (API) • Win16 - Windows 3.1 [Segmented Memory] • Win32 - Windows 95/98/NT/2000/XP [Flat Memory] • Differences between 9X & NT families • Unsupported functions [Security, etc.] • Unicode vs ASCII • All windows programs use the API, but not all equal • API is C-centric, some things are difficult in VB • Programs are monolithic, can't be part VB, part C • MS .NET is "unified API" on top of Win32
.NET (From our perspective) • An execution environment • Called the CLR • Converts MSIL tomachine code • Responsible forsecurity, etc. • A class library • Common to VB, C#"managed" C++, etc. • Translators or languages
What are .NET Programs? • .NET programs can be written in any language • C#, VB.NET, and Managed C++ come with VS • Next version will also have J# • All .NET languages use the same class library • Don't use standard VB or C++ library • .NET Framework Class Library replaces built-in library • Means you always write Console.Writeln("Hi"); • Called the .NET Foundation Class Library (FCL) • Rich set of features -- similar to Java Class Libraries
MSIL and Common Type System • All .NET languages produce "virtual" machine language • Called MSIL or Microsoft Intermediate Language • Similar to Java bytecode targets the Java Virtual Machine • MSIL is converted to machine code when loaded • All .NET languages use a Common Type System (CTS) • Language-specific types are mapped to .NET types • Value types : primitives and structs (records) • Reference types : objects, pointers, interfaces • How cross-language interoperability is achieved
How Translation Works in .NET Development VB C# Script ... Assembly: MSIL + Metadata Install timeCode Gen Deployment Common Language Runtime JITCode Gen NativeCode
Result is Managed by CLR • CLR (Common Language Runtime) is heart of .NET • ALL .NET Code is Managed • .NET cannot run unmanaged code or use legacy library • You cannot write: cout << "Hi"; for instance • You can, currently, run both .NET and unmanaged code • What does CLR do? • Provides compilation and class loading • Handles security, range-checking, exceptions • Provides garbage collection • Thread support, class library interfaces, COM support
What is Visual Studio .NET? • Visual Studio .NET • Integrated Development Environment (IDE) • Program in a variety of .NET languages • C#, VB.NET, Managed C++ • Tools to edit and manipulate several file types • Source code editor • Debugger • Compiler • Visual GUI builder • Resource editor
The Start Page • The Start Page • Links on left side • Getting Started screen • Links to recent projects • The Open Project button • The New Project button • TheWhat's Newscreen • Updates for Visual Studio • Code samples • New tools • Tutorials and Tips
Start-Page Links II • TheOnline Communityscreen • Newsgroups, user groups, chats, components • The Headlines screen • New articles, white-papers, etc. • The Search Online screen • Search screen for MSDN library • The Downloads screen • Updates and code samples
Start-Page Links III • The XML Web Services screen • Information about Web services (Chapter 21) • Reusable services available over the Internet • The Web Hosting screen • Programmers can post software for public use • The My Profile screen • Allows Visual Studio .NET customization • Keyboard preferences • Window layout preferences
Our First App • Let's build the program from Section 2.6 (p.44) • Form to hold other controls • Label to display text • PictureBox to display a picture • No code needed to create this program
Project type Project name Click to change project location Project location Step 1 : Create the Project • Click New Project button or use File > New > Project
The New Projects Dialog • New project dialog • C# .NET project • Group of related files, images, and documentations • C# .NET solution • Group of projects creating one or a group of applications • Windows Applications • GUI applications that run under the Windows OS • Microsoft Word • Microsoft Internet Explorer
Name and Location • Make the project a C# Windows Application • Name it ASimpleProject • Store it on your local folder (U:\) Select project location Click to set project location
IDE Tour I menu title bar tabs menu bar active tab Solution Explorer Form (windows application) Properties window
IDE Tour II - Form & Tabs • IDE after a new project • "Design Mode" supports form-based visual design for all .NET languages. (Like Visual Basic) • The form • Grey rectangle in window • Represents the project’s main window • Part of the GUI or Graphical User Interface • Tabs • One tab appears for each open document • Used to save space in the IDE
IDE Tour III - Menus & Toolbar • The menu bar • Commands for developing and executing programs • Create new project using File > New > Project • Certain menu options only appear in specific IDE modes • Each menu is summarized in Fig. 2.5 (page 38) • The toolbar : common commands • Note down arrows for additional commands • Display tool tips by hovering mouse
IDE Tour IV - Solution Explorer • A "Solution" is .NET-speak for multi-project, project • Project can have multiple files, all same language • Solution Explorer is the "file manager" for solution • Use it to navigate through projects/files • Expand/collapse like Windows Explorer • Can also double click on the file name to expand/collapse • Solution Explorer toolbar • Refresh icon reloads files in the solution • Display All Files icon shows hidden files
IDE Tour VI - Properties Window • Manipulate the properties of a form or control • Each control has its own set of properties • Size, color, text, or position • Left column property, right value • Users alter controls visually without writing code • component selection dropdown list shows what control is being altered and controls available
Name and type of object Selected property Property value Property description Step 2 : Change the Text Property • Let's change our form’s title bar • Use the Properties window • Locate the Text property • Set the value to: A Simple Program
Step 3 : Resize the Form • Click and drag one of the forms size handles • Enabled handles are white, disabled ones are gray • The grid in the background will not appear in the solution Title bar grid Disabled sizing handle Mouse pointer over a sizing handle Enabled sizing handle
Step 4 : Change the Background • Determined by the BackColor property • Dropdown arrow is used to set the color • Change it to Yellow on Custom tab Custom palette Down arrow Current color
toolbox group controls scroll arrow Adding a Component • Want to add a Label control to the form • Controls can be dragged to the form from the Toolbox • Also added to the form by double clicking • The Toolbox contains reusable controls • Controls customize the form • Visual programming allows ‘drag and drop’ of controls • Pointer icon deselects current control • No tool tips, each icon is labeled
More Toolbox Info • Toolbox is organized into groups • Toolbox can be hidden on left side of IDE • Mouse over it to expand it, move mouse to hid • The pin icon is used disable auto hide close button toggle auto hide mouse over window name
Step 5 : Add a Label • Open the Toolbox • Drag and drop the Labelcontrol on the form • Set the label’s text • Use the Text property • Position by dragging, oruse menu commandFormat > Center In Form > Horizontal
Step 6 : Change Font • Set the label’s font size • The Font property changes label’s text • Select font fromstandard Windowsfont selection dialog • Make the text24 Point Sans Serif
Step 7 : Align Label on Form • Use the TextAlign property to align the label • Align it Top-Center by clicking on the appropriate bump • Doesn't seem to resize, does it? Text alignment option Top-center alignment option
Step 8 : Add the PictureBox • Drag PictureBox control to the form • Used to display pictures • Insert an image • Use Image property • Click ellipsis, pick fileof type .gif, .jpeg, or .png • Resize box to fit the entire image
Step 9 : Save, Run, & Quit • Save the project • Use Toolbar Save All orFile > Save All from Menu • Run the project • Use Toolbar Start (VCR), orClick Debug > Start orPress the F5 key • To stop, just close the windowor press Stop button in Debug toolbar