Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Tutorial: C# Hello World

form hello world

  • Please log in to reply
15 replies to this topic

#1 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 23 September 2006 - 10:58 AM

In this tutorial I will show you how to create the basic "Hello World" program using one form, a button and the messagebox class.

1) Load up Visual Studio 2005 or Visual C# Express Edition.
A. Click File/New Project
B. Select Windows Application
C. Type in the name of the project. I used "Hellow World"

Posted Image


2) You should now have Form1 loaded into the IDE with panes to each side of the form. The next thing we are going to do is add a button. To add a button move your mouse over the toolbox which is a tab. This should be on the right hand side as a little tab. This location may be changed though. Refer to the next image if you can not find the tab.

3) Once you see the new pane appear click on "button"

Posted Image


4) Move your mouse over to Form1 in the center of your screen. Click and hold down the mouse button and drag the mouse to the desired dimensions of the button you want.

Posted Image

5) Now that we have our button created we need to add our method to make the "Hello World" message appear. The easiest way to create this method is to simply double-click on the new button. Once you have double-clicked on "button1" you should have code that looks like this:

 private void button1_Click(object sender, EventArgs e)
        {

        }

5) In between the two brackets ( { and } ) add this code:

MessageBox.Show("Hello World");

Your code should look like this:
private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World");
        }

6) Press F5 to run your program. Once the program appears on the screen press button1 and a messagebox should appear.

Posted Image

And that completes the tutorial. From here you can start to play around and change things like the text of the button by right-clicking on the button and selecting properties. A properties pane will appear on the right side of the IDE. Find the Text Field and change it from button1 to anything you like.

I've attached an example of this tutorial as well. In order to download you must be a registered member.

Attached Files


  • 0

#2 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 23 September 2006 - 11:04 AM

Hmm I was going to make that in VB! I will make it tomorrow I think!
  • 0

#3 Lop

Lop

    Speaks fluent binary

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1112 posts

Posted 26 September 2006 - 05:42 AM

Nice tutorial - very detailed. Rep Give!

Tcm - I say make it man! Love your tutorials as well.
  • 0

#4 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 26 September 2006 - 10:33 AM

Hmm thatnks for loving them :) but now school started :( and I dont have much free time!! sorry but will make em soon!
  • 0

#5 Ronin

Ronin

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 302 posts

Posted 28 September 2006 - 04:54 AM

Very nice tutorial. This should help out the newbs.
  • 0

#6 terabite

terabite

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 21 November 2006 - 08:56 AM

im really interesting in your tutorial but i dont have visual studio 2005 nor visual c sharp xpress edition. ive seen visual studio 2005 for download but its very big....could u recommend some thing a little smaller that might be able to work with your tutorial...
  • 0

#7 Paradine

Paradine

    CC Regular

  • Just Joined
  • PipPipPip
  • 48 posts

Posted 21 November 2006 - 09:17 AM

What type of connection are you on? I would recommend downloading VS Express Edition - just let it go all night if you are on a slow connection.

Here is a list of Free C# Compilers that you may want to get:

http://www.thefreeco...rs/csharp.shtml
  • 0

#8 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 21 November 2006 - 09:19 AM

Hmm Im gonna try this coz im really interested in learning this language!! coz I think that VB nowadays isn't used so much, so ill try to switch languages slowly!
  • 0

#9 xXHalfSliceXx

xXHalfSliceXx

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1561 posts

Posted 21 November 2006 - 11:14 PM

Nice. Maybe ill get the program to just mess around
  • 0

Posted Image
Posted Image


#10 Cosmet

Cosmet

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 58 posts

Posted 28 November 2006 - 06:24 AM

Might as well, it is free! :)
  • 0

#11 kresh7

kresh7

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 326 posts

Posted 04 November 2007 - 09:06 AM

nice one
  • 0

#12 Sharper

Sharper

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 25 June 2008 - 07:12 AM

-----------------------------------
  • 0





Also tagged with one or more of these keywords: form, hello world

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download