How to show a form?

  • 13 years ago

    Hello,

    what code do I need to show (make visible) Form B by a mousclick event from Form A?

    As I'm experienced with BorlandBuilder and Visual Basic, now learnig C# I have to re-invent the wheel... finding no propery like 'Show' or 'Visible'.

    Is there some Web C# quick-tutorial on all of these (little) questions?

    Regards,

    Henk

     

  • 13 years ago

    Hi,

    To show the Form B from A creat an instance to the Form B in the Form A and add the code: instance.show();

    for ex: in the Form B if there is a button view

    then in the Form A , button1_click: Form B v;

                                  v=new Form B();

                                  v.show(); 

     

     

  • 13 years ago
    gopinag wrote:

    Hi,

    To show the Form B from A creat an instance to the Form B in the Form A and add the code: instance.show();

    for ex: in the Form B if there is a button view

    then in the Form A , button1_click: Form B v;

                                  v=new Form B();

                                  v.show(); 

     

     

  • 13 years ago

    There are two main ways to show a form:

    1) non-modal display of form:  here the child form and parent form are both active and can accept input.

    private void ShowForm2_Click(object sender, EventArgs e)

    {

             Form2 myForm2 = new Form2();

             myForm2.Show();

    }

    2) modal display of a form:  here once the parent activates the child form with myForm2.ShowDialog(), only the child can accept user input.  The parent is frozen until the child form closes.  Code is frozen on the parent form at the ShowDialog call til the child form closes.  The child form can then pass a dialog result to the parent form (which button was pushed on the child form) via the result of the ShowDialog method.  Note that the child form is not destroyed and must be disposed of by the coder.  I use a using block to automatically close the child form when I'm done with it:

    private void ShowForm2_Click(object sender, EventArgs e)

    {

             // create a child form in a using block so it will be disposed of when done

             using (Form2 myForm142 new Form2())

             {

                      if (myForm2.ShowDialog() == DialogResult.OK)

                      // my parent form code is stuck here til the child form complete's its

                      // action and returns a dialogResult.

                      {

                               // do stuff here if the user pressed the "OK" button on the child form

                      }

             }

    }

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout