0

I was wondering how you would go about opening a form that you have already made from the first form. For example, in a .vb project, I can create two forms, and simply do form2.Show(), and it will show the form with everything I've added to it, etc.. In c#, how would you do this? I've done this so far, because I haven't found another way:

private void menuBar_CheckForUpdates_Click(object sender, EventArgs e)
{
    Form updateForm = new Form();
    updateForm.Show();
}

However, I want to be able to open the form I created manually, and added controls to. How would I do this? I would rather not place all the controls on the new form in code.

dub stylee
  • 3,252
  • 5
  • 38
  • 59
  • I would suggest doing a google search on the following `C# adding Controls Dynamically at RunTime` also if you are not familiar with C# there are some really good tutorials online that you can quickly get yourself up to speed.. understand the basics before you can move on to the more advanced.. – MethodMan Feb 15 '16 at 17:14
  • `Form2 updateForm = new Form2();` - `updateForm.Show();`. – Visual Vincent Feb 15 '16 at 17:17
  • Your code already seems to be correct - although from the answers and comments so far your question is being interpreted in a number of different ways. Can you make it less ambiguous? eg are you talking about adding controls at runtime? – peterG Feb 15 '16 at 17:22
  • Sorry about that. What I mean is, let's say I create a new form in the solution explorer (not while the program is running) and I call it updateForm.cs Now let's say I drag on a text box, and a label, etc.. So It's not a blank form anymore. Well in a .vb form, I could just do updateForm.Show() and it would show the form a created, with all the controls I dropped onto it. Well I want to do the same with the .cs form. But the only thing i've been able to do right now is create a new form, create a new text box, and assign it each time. Hope that makes more sense. –  Feb 15 '16 at 17:29
  • 1
    @DonaldCox : You get a new form because you keep declaring an empty form. Do this instead: `updateForm updateFrm = new updateForm(); updateFrm.Show();`. – Visual Vincent Feb 15 '16 at 17:38
  • Thanks! That fixed the issue. –  Feb 15 '16 at 17:39
  • The VB.NET equivalent for example, would be `Dim updateFrm As New updateForm`. – Visual Vincent Feb 15 '16 at 17:39
  • 1
    Yet another case of a VB 'feature' (default form instances) hampering programmer development. But it does save 1 line of code ! – Dave Doknjas Feb 15 '16 at 18:02

1 Answers1

2

Every form you create in the designer is a normal class (with a designer-generated method that creates the controls).

You can create an instance of that class and Show() it.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964