DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Open Same forminstance Multiple times (http://www.daniweb.com/forums/thread115525.html)

Jennifer84 Mar 24th, 2008 10:44 pm
Open Same forminstance Multiple times
 
I wonder how it is possible to open 2 instances at the same time of a Form.
Normally when you ex press a button to open another form, one instance of that form is opened.

If I put these 2 lines inside a buttoncontrol, first one instance is opened and when I close this opened form, then the next line executes and the same form opens again.

How could it be possible to open both at the same time, so I have 2 instances open ?

this->form2instance.ShowDialog();
this->form2instance.ShowDialog();

vijayan121 Mar 25th, 2008 12:31 am
Re: Open Same forminstance Multiple times
 
Form::ShowDialog()
shows the form as a modal dialog box. (the code following it is not executed until after the dialog box is closed.)
to show two instances of the same form:
a. create two instances of the Form (you seem to already have one instance, so create one more)
b. call
Form::Show()
on each of them.

Jennifer84 Mar 25th, 2008 3:16 pm
Re: Open Same forminstance Multiple times
 
Yes, that seems logic.. thanks. I have created 2 instances now like this where I try to open 2 at the same time with the button2_Click_3 below but the same thing is happening here again.
First form21instance is opened and then when I close this instance, form22instance is opened.
Any idéas what this could depend on ?


public ref class Form3 : public System::Windows::Forms::Form
{
        private: Form2 form21instance;
        private: Form2 form22instance;
}
private: System::Void button2_Click_3(System::Object^  sender, System::EventArgs^  e) 
 {
        this->form21instance.ShowDialog();
        this->form22instance.ShowDialog();
 }

Quote:

Originally Posted by vijayan121 (Post 568454)
Form::ShowDialog()
shows the form as a modal dialog box. (the code following it is not executed until after the dialog box is closed.)
to show two instances of the same form:
a. create two instances of the Form (you seem to already have one instance, so create one more)
b. call
Form::Show()
on each of them.


Jennifer84 Mar 25th, 2008 7:56 pm
Re: Open Same forminstance Multiple times
 
I have also tried to open another form at the same time.
So in this case I will actually open 2 different "Forms" in my application.
(Form2 and Form4).
When pressing the button, first Form2 is opened and when closed, then Form4 will open.
I cant figure out what this is depending on, though I want both forms to open at the same time.


public ref class Form3 : public System::Windows::Forms::Form
{
        private: Form4 form4instance;
        private: Form2 form22instance;
}
private: System::Void button2_Click_3(System::Object^  sender, System::EventArgs^  e) 
{
        this->form22instance.ShowDialog();
        this->form4instance.ShowDialog();
}

mitrmkar Mar 25th, 2008 8:18 pm
Re: Open Same forminstance Multiple times
 
Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
private: System::Void button2_Click_3(System::Object^  sender, System::EventArgs^  e) 
{
        this->form22instance.Show();
        this->form4instance.Show();
}

Jennifer84 Mar 25th, 2008 8:51 pm
Re: Open Same forminstance Multiple times
 
Yes, I totally missed that. Ofcourse, .Show() works fine.
Thank you...


Quote:

Originally Posted by mitrmkar (Post 569085)
Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
private: System::Void button2_Click_3(System::Object^  sender, System::EventArgs^  e) 
{
        this->form22instance.Show();
        this->form4instance.Show();
}



All times are GMT -4. The time now is 2:04 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC