| | |
this->form2instance.Show();
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
I have this code that opens a Form. This code does work but if I just close the Form that did open with this code and press the button5 again, I will have an Errormessage:
"Cannot access a disposed object. Object name: ´Form2´."
But if I change:
this->form2instance.Show();
to:
this->form2instance.ShowDialog();
Then it does work, I can open the Form2 and close it, open it again and so on.
The thing is that I need to use the code below because I will have to open many instances of the same Form.
"Cannot access a disposed object. Object name: ´Form2´."
But if I change:
this->form2instance.Show();
to:
this->form2instance.ShowDialog();
Then it does work, I can open the Form2 and close it, open it again and so on.
The thing is that I need to use the code below because I will have to open many instances of the same Form.
C++ Syntax (Toggle Plain Text)
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) { this->form2instance.Show(); }
Last edited by Jennifer84; May 12th, 2008 at 10:23 am.
Typically all the forms you create in the IDE are automatically created when your application starts. (You can choose which forms are auto-created from the Project->Options menu.) You can see the code that does it by choosing Project->View Source (to see the WinMain() function).
What appears to be happening is that you are Free()ing the form when it is closed, and you can no longer Show() an object that has been destroyed.
From what I understand that you want to do, you should go to the project options and remove the Form2 from the auto-create list. (You can also delete the Form2 variable from the unit source file.)
Next, in your button click handler, (1) create a new instance of the form and (2) show it.
Now you can click the button to get as many copies of TForm2 as you want, and closing each one should still delete the individual instance.
Hope this helps.
What appears to be happening is that you are Free()ing the form when it is closed, and you can no longer Show() an object that has been destroyed.
From what I understand that you want to do, you should go to the project options and remove the Form2 from the auto-create list. (You can also delete the Form2 variable from the unit source file.)
Next, in your button click handler, (1) create a new instance of the form and (2) show it.
C++ Syntax (Toggle Plain Text)
System::Void Form1::button5_Click(System::Object^ sender, System::EventArgs^ e) { TForm2 newForm; Application->CreateForm( TForm2, newForm ); // (1) newForm.Show(); // (2) }
Hope this helps.
Last edited by Duoas; May 12th, 2008 at 2:08 pm.
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
I have deleted the Form2 variable from the unit source file.
Then I have written this in the button5_Click event handler.
If I write TForm2 newForm as described before, this will be an undeclared identifier.
But Form2 newForm; compiles.
I cant find ->CreateForm as a member to Application.
I have to write Application:: to find any members at all but here, I cant find "CreateForm".
I am not sure if I am doing right or if I could do something else.
Thanks...
Then I have written this in the button5_Click event handler.
If I write TForm2 newForm as described before, this will be an undeclared identifier.
But Form2 newForm; compiles.
I cant find ->CreateForm as a member to Application.
I have to write Application:: to find any members at all but here, I cant find "CreateForm".
I am not sure if I am doing right or if I could do something else.
Thanks...
C++ Syntax (Toggle Plain Text)
Form2 newForm; Application->CreateForm( Form2, newForm); newForm.Show();
•
•
•
•
Typically all the forms you create in the IDE are automatically created when your application starts. (You can choose which forms are auto-created from the Project->Options menu.) You can see the code that does it by choosing Project->View Source (to see the WinMain() function).
What appears to be happening is that you are Free()ing the form when it is closed, and you can no longer Show() an object that has been destroyed.
From what I understand that you want to do, you should go to the project options and remove the Form2 from the auto-create list. (You can also delete the Form2 variable from the unit source file.)
Next, in your button click handler, (1) create a new instance of the form and (2) show it.
Now you can click the button to get as many copies of TForm2 as you want, and closing each one should still delete the individual instance.C++ Syntax (Toggle Plain Text)
System::Void Form1::button5_Click(System::Object^ sender, System::EventArgs^ e) { TForm2 newForm; Application->CreateForm( TForm2, newForm ); // (1) newForm.Show(); // (2) }
Hope this helps.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
Below is one option, maybe that is what you are after
C++ Syntax (Toggle Plain Text)
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^form2 = gcnew Form2; form2->Show(); }
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
This works great.
•
•
•
•
Below is one option, maybe that is what you are after
C++ Syntax (Toggle Plain Text)
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^form2 = gcnew Form2; form2->Show(); }
![]() |
Other Threads in the C++ Forum
- Previous Thread: ScrollBar on Form
- Next Thread: Please help!
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






