Search code examples
c#.netvisual-studiowinformsdesigner

How Do You Edit a Second (Non-Main) C# Form Window In Visual Studio Designer?


I am writing a C# Windows Forms program in Visual Studio. I have a button that creates and shows (opens) a new Form (window) called VideoWindow. I can edit the MainWindow in the Design workspace in Visual Studio which allows me to visually edit its contents. However, I can't find a way to do the same thing with the VideoWindow. I have tried right clicking on VideoWindow and clicking View Designer, but it just takes me to the MainWindow designer. How do I open the designer for the second VideoWindow? Is this possible? Below is the code that creates and opens the new form:

    private void ButtonWindow(object sender, EventArgs e)
    {
        Form VideoWindow = new Form();
        VideoWindow.Size = new Size(500, 300);
        VideoWindow.Show();
    }

Edit: I know you can (and usually should) access the Designer when you create a form through the Visual Studio wizard via Project -> Add Form. However my question was for if you manually write a form class like NewForm.cs. In that case there would be no auto-generated NewForm.Designer.cs file.


Solution

  • You can customize a new form, and then create the corresponding object after modification. Here are the relevant steps:

    1.Create a new form videoform enter image description here

    2.Relevant code:

    .Show(); and .ShowDialog(); Note the difference between the two.

    private void button1_Click(object sender, EventArgs e)
    {
        VideoWindow videoWindow = new VideoWindow();
        videoWindow.Show();
        //videoWindow.ShowDialog();
    }
    

    3.Ouput: enter image description here