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.


To create a C# application

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

  2. Select the Windows Forms Application template. In the Name field, type MyFirstProject, 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 control onto the form, near the label.

  6. Double-click the new button, button1, to open the file Form1.cs.

  7. In Form1.cs, look for a method called button1_Click. Method button1_Click is run when button1 is clicked.

  8. Add the following statement as the body of button1_Click.

    // Insert this line as the body of method button1_Click.
    label1.Text = "Hello, World!";

    The complete method should look like this:

    private void button1_Click(object sender, EventArgs e)
        // Insert this line as the body of method button1_Click.
        label1.Text = "Hello, World!";
  9. Press F5 to compile and run your application.

    When you click button1, a text message is displayed. Congratulations! You have just written your first C# application.

See Also

Other Resources

Visual C#

Getting Started with Visual C#

Change History




December 2009

Clarified steps 6, 7, and 8.

Customer feedback.