Visual C# Getting Started
Creating Your First C# Application

It only takes a minute to create a C# application. Follow these steps to create a program that opens a window and reacts to a button press.

Procedures

To create a C# application

  1. On the File menu, point to New, and then click Project.

  2. Ensure that the Windows Forms Application template is selected, in the Name field, type MyProject, and click OK.

    You will see a Windows Form in the Windows Forms designer. This is the user interface for your application.

  3. On the View menu, click Toolbox to make the list of controls visible.

  4. Expand the Common Controls list, and drag the Label control to your form.

  5. Also from the Toolbox Common Controls list, drag a button onto the form, near the label.

  6. Double-click the new button to open the Code Editor. Visual C# has inserted a method called button1_Click that is executed when the button is clicked.

  7. Change the method to look like this:

    private void button1_Click(object sender, EventArgs e)
    {
        label1.Text = "Hello, World!";
    }
    
  8. Press F5 to compile and run your application.

    When you click the button, a text message is displayed. Congratulations! You've just written your first C# application.

See Also

Other Resources



Community Content

Thomas Lee
Hello World

As a developer you'll often code console applications to validate a possible implementation path before you invest in win, web, or mobile application designer time.

My first application was a console application:

  1. On the File menu, point to New, and then click Project.

  2. Ensure the Console Application template is selected, in the Name field, leave ConsoleApplication1, and click OK.

  3. Change the method to look like this:

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
        Console.Read();
    }
    
  4. Press F5 to compile and run your application.

    The words Hello World display. Hitting Enter will end the application closing the console.

Tags : contentbug

Thomas Lee
Couldn't get it to work in VS2008
If you are getting an error in VS2008 it could be that that Text is no longer associated with the XAML <label> tag. Try switching <label> to <TextBlock> and everything else works out.

Tags :

GeneraL Hamdy
A Hint For Newbs.
First time i copy+pasted
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Hello, World!";
}

just after i doubleclicked the "new button". - and ofcourse it didn't work.
just copy+paste

label1.Text = "Hello, World!";
and everything should be fine.

Tags :

DaveStar.net
For beginners

Reply to:
This was labelled for beginners. It asks you to change a method without showing you where to change the line of code or what a method is. You aren't sure of where to change the code, but every variation I've tried doesn't work. WTF. Why have this on here?


My reply:
Well i am a java developer and have just started learning C# and i perfectly understood what the author was trying to convey in this startup example! Are you trying to learn C# or just "computer programming" ? why not do a lil bit of self study before blaming anyone. wish u good luck.

-------------------------------------------------------------------------------------------------------------------

YES, this is not well written. If you want this to work open a new project drag and drop a label and also a button on to the blank project. Once the two objects are there double click on the button object and you will see this.


Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub
End Class


On the code page enter this text into the button1 click.

Label1.Text = "Hello"

So your code page should now look like this.


Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello"
End Sub
End Class



Hopefully someone new will be able to at least get this application working.

Dave Star

Tags : c# csharp basics

Page view tracker