C# tutorials
3. Hello world with menu

Note: While reading this page, bear in mind that I'm no computer expert and that the text below may be partly inaccurate. If you find errors or have proposals for improvements, please send me a message and help make this a better page for the benefit of future visitors. To the left, there are links to more C# tutorials.


To complete this tutorial, follow these instructions:

1. Open Visual C# 2010 Express.

2. Click on New Project in the File menu.

3. Choose Windows Forms Application if that option isn't already chosen, change the name if you like and click on OK.

4. Point at Toolbox in the left margin and click on the Auto Hide icon at the top of the window (to keep the window to stay open and easier to work with).

5. Drag a Rich Textbox to Form 1. Resize the textbox if you like.

6. Drag a MenuStrip to Form1. It will appear at the top of Form1 and at the bottom of the screen as menuStrip1.

7. In Form1, click on Type Here and write a name for the menu, for example Hello.

8. Click on Type Here below Hello (or whatever you have written) and write a name for the menu item, for example Hello World.

9. Right-click on Hello World (or whatever you have written) and click on Properties. This will take you to the Properties window and make it possible to change the settings for the menu item Hello World (or whatever you have written).

10. At the top of the properties window, click on the Events icon (it looks like a flash).

11. Double-click on Click. The file Form1.cs will open with the caret ready to write code that will run when the menu item Hello (or whatever you have written) is clicked.

12. Write or paste this code where the caret is:

richTextBox1.Text = "Hello world!";

13. Press F5 to start debugging the program.

14. Click on Hello World (or whatever you have written) in the Hello (or whatever you have written) menu. The text Hello world! should appear in the textbox.

Comment

Instead of doing step 9-11, you should be able to double-click on Hello World (or whatever you have written). However, it seems double-clicking on menu items to get to the source code doesn't work most of the time. At least, that's my experience.


Would you like to comment on this page or some other page? Use the contact form. Write the title of the page you want to comment on and your comment in the field Message.