Jump to content

Tutorial: C# Hello World

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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



#2
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Hmm I was going to make that in VB! I will make it tomorrow I think!

#3
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Nice tutorial - very detailed. Rep Give!

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

#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Hmm thatnks for loving them :) but now school started :( and I dont have much free time!! sorry but will make em soon!

#5
Ronin

Ronin

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 309 posts
Very nice tutorial. This should help out the newbs.

#6
terabite

terabite

    Newbie

  • Members
  • PipPip
  • 14 posts
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...

#7
Paradine

Paradine

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
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

#8
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
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!

#9
xXHalfSliceXx

xXHalfSliceXx

    Speaks fluent binary

  • Moderators
  • 1,694 posts
Nice. Maybe ill get the program to just mess around

Posted Image
Posted Image


#10
Cosmet

Cosmet

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts
Might as well, it is free! :)

#11
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
nice one

#12
Sharper

Sharper

    Newbie

  • Members
  • Pip
  • 1 posts
-----------------------------------