Open Same forminstance Multiple times

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Open Same forminstance Multiple times

 
0
  #1
Mar 24th, 2008
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 ?

  1. this->form2instance.ShowDialog();
  2. this->form2instance.ShowDialog();
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Open Same forminstance Multiple times

 
0
  #2
Mar 25th, 2008
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.
Last edited by vijayan121; Mar 25th, 2008 at 12:32 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Open Same forminstance Multiple times

 
0
  #3
Mar 25th, 2008
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 ?


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

Originally Posted by vijayan121 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Open Same forminstance Multiple times

 
0
  #4
Mar 25th, 2008
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.


  1. public ref class Form3 : public System::Windows::Forms::Form
  2. {
  3. private: Form4 form4instance;
  4. private: Form2 form22instance;
  5. }
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.ShowDialog();
  4. this->form4instance.ShowDialog();
  5. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: Open Same forminstance Multiple times

 
0
  #5
Mar 25th, 2008
Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.Show();
  4. this->form4instance.Show();
  5. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Open Same forminstance Multiple times

 
0
  #6
Mar 25th, 2008
Yes, I totally missed that. Ofcourse, .Show() works fine.
Thank you...


Originally Posted by mitrmkar View Post
Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.Show();
  4. this->form4instance.Show();
  5. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC