Lost Password?


  #1 (permalink)  
Old 01-30-2008, 05:38 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,224
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Visual Studio 2008: C# Hello World Tutorial

In this tutorial I'll show you how the Visual Studio IDE works using C#. In the end you will create a program that displays the traditional "Hello World" message.

Loading Visual Studio 2008
Once you have completed the installation, which can take a while, load Visual Studio 2008. You will find it under Start/All Programs/Microsoft Visual Studio 2008/Microsoft Visual Studio 2008. If this is the first time you have ran VS2008 you will need to select a default language. I chose C++ but if you are interested in C# choose that. Your layout may look a little different than mine.

Once all of the initialization has finished you will see the Visual Studio 2008 Start Page pictured below.



In the left column you can see the Solution Explorer and a tab at the bottom labeled Class View.

Solution Explorer
Solution Explorer provides you with an organized view of your projects and their files as well as ready access to the commands that pertain to them. A toolbar associated with this window offers commonly used commands for the item you highlight in the list. To access Solution Explorer, select Solution Explorer on the View menu.
Source

Class View
Class View displays the symbols defined, referenced, or called in the application you are developing. You can open Class View from the View menu. There are two panes: an upper Objects pane and a lower Members pane. The Objects pane contains an expandable tree of symbols whose top-level nodes represent projects. To expand a node selected in the tree, click its plus (+) sign or press the plus (+) key on the keypad.

Icons identify hierarchical structures employed within your projects, such as namespaces, types, interfaces, enums, and classes. You can expand these structures to list their members. Properties, methods, events, variables, constants, and other contained items are listed in the Members pane.

This hierarchical, project-by-project, view clarifies the symbolic structures within your code. You can use Class View to open files and navigate directly to the lines where symbols appear.

Source

On the Right..
You can see the Properties Window and two tabs, Toolbox and Server Explorer (these tabs are vertical along the upper right hand corner). The properties window displays sizes, dimensions and other "properties" for objects. The Toolbox tab is where you select components and add to your form. For a more in depth guide on using the IDE I suggest you pick up a good book or even take a class.


Lets Make Our Program
Select File/New/Project and the New Project window will appear. Select Visual C#. If you don't see this option you may have to click the plus (+) beside Other Languages. This is because you have selected a default language other than C#. Highlight Windows Forms Application. Change the name to HelloWorld which will also change the solution name at the same time. Your window should look like mine:




Click the OK button.

Designing the Application

You should now see a new new tab in the center labeled Form1.cs [Design]* next to the Start Page. In the center of the window you can see your new form respectively named Form1. Click directly on this. A dotted line will appear around it and the Properties Window will fill with values.

The first thing you should do is name your form appropriately. Find (Name) in the properties window (you may need to scroll) which should have a value of Form1. Change the value to frmMain. Preceding the names of your objects with what they are (frm = form) will create legible, clean code that is easy to read when you edit your code 1 month later. In this tutorial all objects will have a preceding name which specifies what they are.

The 2nd thing you should change is the text of your form which currently states Form1. The text label is simply the "title" of your form. Scroll down (or up) in the properties view until you find Text with a value of Form1. Change the value to "Hello World".




Adding functionality
Mouse over the Toolbox tab on the right hand side to view the objects you can use:




Click on Button. Place your mouse cursor over the center of your form (frmMain), left-click and hold. Move your cursor to the right and bottom to create a square. Release the mouse button. You should now see a button in the center of your screen with the Text/Title of Button1.




First things First
Click on the button (button1) to see the properties of the object. Find (Name) with the value of button1 and change the value to btnHelloWorld. Scroll down and find Text with the value of button1. Change the value to Click Me.

You have now created a button and properly named/labeled it. The next step is adding the code that makes it work. Double click the button (btnHelloWorld) in the center of your form. This actually creates the button click event function and brings up the code window.




Your cursor is directly below the opening curly bracket { and directly above the closing bracket }. The first thing you should do when a new function is created is comment the code. The Visual Studio 2008 IDE has built in functions that assist you in this task. Press the up arrow three times. Press Enter once. Now press the forward slash (/) three times. As you left of the forward slash the third time XML comments are created for entering function data. Your cursor will be between the summary tags. Enter here what the function below will do. Our function will create a message box with the text "Hello World". Hence, enter:

Code:
///<summary>
/// Function to create Message Box with 
/// text "Hello World".
/// </summary>
Notice as you press enter three new forward slashes (/) are entered automatically and your cursor is indented to the correct place. This is one of the great features of the VS IDE, automatic indention. You may not appreciate it much now but if you ever do work in Notepad or a similar non programming text editor you will learn how much it helps.

Move your cursor down below the function btnHellowWorld_Click:

Code:
private void btnHelloWorld_Click(object sender, EventArgs e)
        {
Your cursor should be just below the opening bracket { and just above the closing bracket }. Type MessageBox.Show("Hello World");. Notice the autofill drop down that appears. Another feature of the Visual Studio suite that you will find very useful in time. As you type functions are highlighted in this autofill, pressing enter before you finish typing will automatically fill the text in for you.




MessageBox Function
Displays a modal dialog box that contains a brief application-specific message, such as status or error information. The message box returns an integer value that indicates which button the user clicked.

Source

Running the Code
There are two ways to run the code:

1) Goto Debug/Start Debugging
2) Press F5

Choose either of the options and your code will be compiled and ran.




Click the button "Click Me". You should see:





Congratulations!
You've created your first Visual Studio 2008 C# Program. You've learned some of the very basics here in this tutorial and I highly recommend getting a Visual Studio 2008 C# Book. If you have any questions or comments please post them here.
Attached Files To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.

Last edited by Jordan; 01-30-2008 at 08:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-27-2008, 08:48 AM
eseph eseph is offline
Newbie
 
Join Date: Feb 2008
Posts: 1
Rep Power: 0
eseph is on a distinguished road
Default

Thanks for this.

Hello World.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-22-2008, 01:34 AM
srbworld srbworld is offline
Newbie
 
Join Date: Aug 2008
Posts: 1
Rep Power: 0
srbworld is on a distinguished road
Default Re: Visual Studio 2008: C# Hello World Tutorial

Thanks a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-22-2008, 01:43 AM
gaylo565's Avatar   
gaylo565 gaylo565 is offline
Programmer
 
Join Date: May 2007
Location: flagstaff, az
Posts: 187
Last Blog:
String Manipulation wi...
Rep Power: 9
gaylo565 is a jewel in the roughgaylo565 is a jewel in the roughgaylo565 is a jewel in the rough
Default Re: Visual Studio 2008: C# Hello World Tutorial

This is an excellent example of a tutorial! Great detail and documentation.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-22-2008, 11:44 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,589
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Visual Studio 2008: C# Hello World Tutorial

When you consider how long it is, the code is kinda basic, but of course this was the point. Well done, +rep.

See, I do give rep.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 11-04-2008, 03:56 AM
tianhui tianhui is offline
Newbie
 
Join Date: Nov 2008
Posts: 1
Rep Power: 0
tianhui is on a distinguished road
Smile Re: Visual Studio 2008: C# Hello World Tutorial

it is easy to understand
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-04-2008, 11:33 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,276
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default Re: Visual Studio 2008: C# Hello World Tutorial

Nice one, Jordan.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-04-2008, 12:04 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,224
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: Visual Studio 2008: C# Hello World Tutorial

Your welcome all.

I suppose this one is just getting popular? It seems it has created several linkbacks from Yahoo and Kizmo. If anyone needs further assistance just let me know.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-17-2008, 11:11 PM
glowinggem888 glowinggem888 is offline
Newbie
 
Join Date: Nov 2008
Posts: 1
Rep Power: 0
glowinggem888 is on a distinguished road
Default Re: Visual Studio 2008: C# Hello World Tutorial

This is really helpful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-18-2008, 06:07 PM
pavonia pavonia is offline
Newbie
 
Join Date: Nov 2008
Posts: 2
Rep Power: 0
pavonia is on a distinguished road
Thumbs up Re: Visual Studio 2008: C# Hello World Tutorial

Excellent Tutorial... Helped a lot!!

Jordan, Thanks a lot...

BTW, is it possible to provide a tutorial describing, how to create a new Web project in VS2008, like this Hello World program?

Like user will go to some URL, provide ID/Password and for successful log-in, he/she will get "Hello <User Name>" message.

Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: C# Hello World Jordan CSharp Tutorials 15 10-16-2008 11:44 PM
Visual Studio 2008 Express Beta 2 Download Jordan Programming News 2 08-03-2007 02:05 PM
Visual Studio 2005 and Windows Vista Jordan General Programming 3 01-22-2007 04:21 PM
Visual Studio 2005 Pro Won't Install CheeseBurgerMan Software Development Tools 10 09-22-2006 06:44 PM
Visual Studio 2005 Express Edition Crane Software Development Tools 9 05-25-2006 07:17 PM


All times are GMT -5. The time now is 11:52 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads