Working with Multiple Forms using Visual C# 2008

You will need to work with more than one form while developing Windows based applications in C#. In this code snippet, Anand examines the steps required using Visual C# 2008

(1) Start Visual Studio 2008 (Start | All Programs | Microsoft Visual Studio 2008 | Microsoft Visual Studio 2008)

(2) Create a new C# project from File | New | Project. The New Project dialog box opens up as shown in Figure 1. Modify the project name and change the target directory if required.

Figure 1

(3) A new form with the title Form1 appears on the screen. Add a Button control to it from the Toolbox. Change the caption to OK by altering the Text property from the Properties window.

Figure 2

2

(4) Add another form to the project by selecting Add Windows Form item from Project menu. Add a Label control to it and change its text as “This is Form 2”

Figure 3

3

(5) Activate Form 1 by double clicking Form1.cs from Solution Explorer. Double click the Button control and add the following code

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">Form2 f2 = new Form2();
f2.Show();

Figure 4

4

(6) Run the project by pressing F5 key. You can also run by selecting Start Debugging item from the Debug menu.

Figure 5

5

READ  What are the different editors that are available for C# programming?

One Response to "Working with Multiple Forms using Visual C# 2008"

  1. beginner   September 21, 2009 at 4:48 am

    Thanks a lot!!!

    Reply

Leave a Reply

Your email address will not be published.