Visual Studio 2008 / Your First C# Program
Subtitles of the Movie
Now let's take a look at your very first C# program. We're going to do a very simple, little program here. We're going to open a message box and what I want you to see is just kind of how to move around and how to manipulate Visual Studio. So we'll click on Start. Notice Visual Studio 2008 is pinned on my Start Menu because I've opened it already. If you don't see that you can go to All Programs, just mouse over to a pop-up, you'll see Visual Studio 2008 if you installed it along with me in the installation video earlier or if you already have it on your machine and I'll choose Visual Studio 2008. Now, notice it opens up to the default settings, whatever yours is. Microsoft wants to know if we want to, if they want to help make Visual Studio better. We don't. We'll click that and let it go. So let's click on Create Project here and if you don't see this for any reason, you're not left out in the cold. You can go up here and click on File, New, Project; takes us to the same place. OK? So either way. We're going to do a Visual C# Windows Forms Application Project. Show you a couple of things here. We will call this VTC Class. Now notice, we can set the location of where we're going to put this, the files or this solution and project and I can click Browse and put it anywhere I would like. I will take the default on this. Notice it's going to put it in Document, Settings, Administrator in my Documents Folder, in the Visual Studio Folder and in a folder called Projects. Now, VTC Class is the name of the solution and we are going to create a new directory for this solution. So now I just click OK. It clicks and hums just a second and you'll notice there is my first application environment set up and ready for me. You will notice since I told it it was going to be a Windows Forms Application, it's already put a form here for me. It is Form1.cs. I can change this if I would like by right clicking and going to Rename but I'm just going to leave it as Form1.cs for now. So let's do something very simple. We will go into the Toolbox. We will double click on the button. You will notice it put one in the upper-left corner of our form and we'll just drag it to the middle. Now, I will change the text on this button to say Click and then I want to change the name of this button so I will scroll up to the name and I will just call this the Click Button and the reason I'm doing that and I just clicked anywhere out here in the white to make that go away, is I want to show you how we can program against this. So now what I want to do is when we double click our, I'm sorry. When we click on this button when the program runs, we want to click up a message box. So I double click on the button and notice that it opens up the code behind page and it's dropped me into the handler for my Click Button Event and notice is says Click Button and so what I'm going to do now is simply say Message and notice Intellisense has kicked in, MessageBox.show and then tell it what I want to put in there. And I'm going to fight the temptation to do Hello World, OK? We'll call it You Clicked. Now, one thing that if you're coming from VB is going to drive you nuts until you get used to it. Notice at the end of the line here we get a red squiggly and if we mouse over that it's going to tell me that it's looking for a semicolon. At the end of every C# line you have to have a semicolon; just the way it is. Go to the next line and so now we go back out to the Form Design, nothing looks widely different out here. We'll reposition that, don't know why I did that but we can do it. And now I will go up here and click on the Run. It will start debugging and you'll notice it's going to run our application and there's our click. We click on it and there's our message box that says You Clicked. Now, ultimately it's that easy to build an application. Now, when we did that, if we look at output down here, notice it's showing me all the stuff that happened and it'll show me that the program ran and so forth. If I look at the error list I don't see anything. Let me go back to Outlook and I'm going to pin this up and what I want to do is run this one more time and you can see some things happening down here that we'll actually look at a little bit later on. But you'll notice that it sees all this stuff loaded, loaded with no problems, we don't see any errors or problems out here and we are ready to go. So that's our first very simple program. That's the basis for how we're going to deal with everything about C#. Now, let me show you one more thing that you need to be aware of. Where did this put this? If I right click on the Properties, on the Project and go to Properties, so right click on the Project and go to Properties, you're going to notice that it put it in an assembly called VTC Class. We don't know what that is. Please don't worry about it. But if I click on Build, this is showing me, this'll actually show me where this application got built. Actually I want to see it right here. Here is the output path. I went brain dead on you there for a minute. I'm thinking VB. But if you click on Build after clicking on Projects, you will notice that it put it in the Bin Debug Folder out there and so if I go out there on my hard disk, go into My Documents, go into Visual Studio 2008, go into Projects, there's VTC Class, go into that folder, go into Bin, go into Debug and there is the actual executable that was built. I'll just show you this right quick. I can drag it out to the Desktop, copy it, then I can double click that from here and there's my application. So C#'s very simple to use. That's a very quick, simple, dirty first application and we're going to build on what we did there and start to add more to C#.
Tutorial Information
| Course: | Introduction to Microsoft C# 2008 |
| Author: | Mark Long |
| SKU: | 34046 |
| ISBN: | 1-935320-78-5 |
| Release Date: | 2009-10-09 |
| Duration: | 7 hrs / 76 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 