943,545 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 684
  • C++ RSS
Mar 24th, 2008
0

Open Same forminstance Multiple times

Expand Post »
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 ?

C++ Syntax (Toggle Plain Text)
  1. this->form2instance.ShowDialog();
  2. this->form2instance.ShowDialog();
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Mar 25th, 2008
0

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.
Last edited by vijayan121; Mar 25th, 2008 at 12:32 am.
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Mar 25th, 2008
0

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 ?


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

Click to Expand / Collapse  Quote originally posted by vijayan121 ...
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.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Mar 25th, 2008
0

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.


C++ Syntax (Toggle Plain Text)
  1. public ref class Form3 : public System::Windows::Forms::Form
  2. {
  3. private: Form4 form4instance;
  4. private: Form2 form22instance;
  5. }
C++ Syntax (Toggle Plain Text)
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.ShowDialog();
  4. this->form4instance.ShowDialog();
  5. }
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Mar 25th, 2008
0

Re: Open Same forminstance Multiple times

Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
C++ Syntax (Toggle Plain Text)
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.Show();
  4. this->form4instance.Show();
  5. }
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007
Mar 25th, 2008
0

Re: Open Same forminstance Multiple times

Yes, I totally missed that. Ofcourse, .Show() works fine.
Thank you...


Click to Expand / Collapse  Quote originally posted by mitrmkar ...
Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...
C++ Syntax (Toggle Plain Text)
  1. private: System::Void button2_Click_3(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. this->form22instance.Show();
  4. this->form4instance.Show();
  5. }
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pointer error
Next Thread in C++ Forum Timeline: deleting a class in visual c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC