Question

So I'm very, very new to C#, and relatively new to programming. I decided to learn by writing a program for my niece, but I'm having a bit of an issue trying to understand how I can manage my "Form2" using the visual designer in VS 2010.

The code I have so far doesn't have a problem running in debug, and the form is launched fine, but I can't find it in the solution explorer. This, I'm sure, has a really simple solution, and I feel stupid for asking it, but I can't find it on Google, or maybe I just don't know how to phrase the question.

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void azbuka_Click(object sender, EventArgs e)
        {
            Form2 azbukatest = new Form2();
            azbukatest.ShowDialog();
        }
    }

    public partial class Form2 : Form
    {
        public Form2()
        {

        }
    }
}
Was it helpful?

Solution

It looks like you defined the second form in the same class as the first, rather than making another full form. If you want the full designer, create a new form using the Add button within the project:

enter image description here

This way visual studio will take care of all the extra details that allow you to utilize the designer and many other perks.

OTHER TIPS

Follow this walkthrough. Next time search and then post questions. This is basic stuff and you can easily find tutorials/walkthroughs.

http://msdn.microsoft.com/en-us/library/vstudio/dd492132.aspx

C# winforms has two components to it, a Designer and Code Behind.

What you've written here is just the code behind, which holds logic, events etc.

The visual form is the designer which holds the UI elements like buttons and textboxes.

Try adding a form using the Visual Studio menus (Add-> New -> Form) in your project, and it will add the dependant files.

Also, if you create a new class, it doesn't come up in the solution explorer as a new file automatically, try looking at the "Class View".

If you want a form generated that you can access in Solution Explorer you should right click on the project name and click Add-> New Item and select Windows Form from there.

This will create a form you can edit in the IDE. Remember to remove

public partial class Form2 : Form
{
    public Form2()
    {

    }
}

before doing this if you want it to be called Form2 (since creating the form via Add Item will create this code for you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top