Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all experts,

I have created 1 form ( frmmain) and 1 folder and in that folder i create 3 forms ( form1,form2,form3 ). in frmmain form, i have some buttons to click and show some info in form1,form2,form3 in folder. i try to declare form1 f=new form1() but i don't see form1 or form2 or form3. i can see only frmmain.

Does anybody know how i can declare and open form1,form2,form3 inside folder?

Thanks

TONY
Posted
Comments
Richard MacCutchan 29-Dec-13 9:12am    
Have you added the other forms to your solution in Visual Studio?
Sergey Alexandrovich Kryukov 29-Dec-13 12:24pm    
What does it mean, "form in folder", "folder creates a form"? A form is just a form, and a folder is just the metaphor concept representing a directory...
And which form do you mean, a Web form, or System.Windows.Forms.Form?
—SA

Try this.
Add a button to frmMain, and handle it's Click event:
C#
private void button1_Click(object sender, EventArgs e)
    {
    Form1 f1 = new Form1();
    f1.ShowDialog();
    Form2 f2 = new Form2();
    f2.ShowDialog();
    }

That will create a new instance of Form1, and display it. When the Form1 is closed, the frmMain will continue and a new Form2 will be displayed.
Then try this:
C#
private void button1_Click(object sender, EventArgs e)
    {
    Form1 f1 = new Form1();
    f1.Show();
    Form2 f2 = new Form2();
    f2.Show();
    }
That will show a new instance of Form1 and Form2 - but it will not wait until they close, frmMain will continue to work.
 
Share this answer
 
hi

C#
private void button1_Click(object sender, EventArgs e)
        {
            var temp = new FolderName.Test();//Folder Name is your Name of your folder
            temp.Show();
        }


Thanks.
 
Share this answer
 
If you are facing problem referencing forms in different folder, then check this out: how-to-reference-a-form-in-another-folder[^]
 
Share this answer
 
Sour Sdey, Tony,

I think people here will understand you better if you use the words "solution, or project," instead of "folder." The word "folder" has the specific meaning of a file-folder in Windows.

In Windows Forms, when you create a Solution/Application: that automatically creates a main Form, titled "Form1," which will be shown automatically when the application is run.

At design-time, in your development environment, like Visual Studio, you can create-and-add other Forms, UserControls, Classes, etc., to your solution.

Forms you declare at design-time must be made visible in code, using, as OriginalGriff shows you how to do in his answer here, 'Show, or 'ShowDialog.

The standard behavior (default) of a Windows Forms Application is that when the Main Form is closed, all other Forms that are active are automatically closed with it.

With Visual Studio, a Solution may have several Projects. And, a Project may be a Class Library (code only), or an executable Application. You tell Visual Studio which Project to start when you run the solution by setting the StartUp Property.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900