Inquiridor
System.ObjectDisposedException

Pergunta
-
Olá pessoal, gostaria de saber porque ocorre este erro quando abro o form2 pela segunda vez.
An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll Additional information: Cannot access a disposed object.
Codigo da aplicação:
#pragma once #include "form2.h" namespace FormAppListView { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form2 ^form2; public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // form2 = gcnew Form2(); } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::ListView^ listView1; protected: private: System::Windows::Forms::ColumnHeader^ columnHeader1; private: System::Windows::Forms::ColumnHeader^ columnHeader2; private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::Button^ button4; private: System::Windows::Forms::Button^ button5; private: System::Windows::Forms::CheckBox^ checkBox1; private: System::Windows::Forms::Label^ label4; private: System::Windows::Forms::ComboBox^ comboBox1; private: System::Windows::Forms::Label^ label5; private: System::Windows::Forms::ComboBox^ comboBox2; private: System::Windows::Forms::GroupBox^ groupBox1; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::Label^ label7; private: System::Windows::Forms::Label^ label6; private: System::Windows::Forms::Timer^ timer1; private: System::Windows::Forms::CheckBox^ checkBox2; private: System::Windows::Forms::Button^ button6; private: System::Windows::Forms::MenuStrip^ menuStrip1; private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem1; private: System::Windows::Forms::ToolStripMenuItem^ settingsToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ creditsToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ decoderzToolStripMenuItem; private: System::Windows::Forms::Label^ label8; private: System::Windows::Forms::ToolStripMenuItem^ decoderzToolStripMenuItem1; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Required designer variable. /// </summary> void test() { MessageBox::Show("Are you okay?", "Ask", MessageBoxButtons::YesNo); } #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); System::Windows::Forms::ListViewItem^ listViewItem2 = (gcnew System::Windows::Forms::ListViewItem(L"test")); System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->listView1 = (gcnew System::Windows::Forms::ListView()); this->columnHeader1 = (gcnew System::Windows::Forms::ColumnHeader()); this->columnHeader2 = (gcnew System::Windows::Forms::ColumnHeader()); this->button1 = (gcnew System::Windows::Forms::Button()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->label1 = (gcnew System::Windows::Forms::Label()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label3 = (gcnew System::Windows::Forms::Label()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->button4 = (gcnew System::Windows::Forms::Button()); this->button5 = (gcnew System::Windows::Forms::Button()); this->checkBox1 = (gcnew System::Windows::Forms::CheckBox()); this->label4 = (gcnew System::Windows::Forms::Label()); this->comboBox1 = (gcnew System::Windows::Forms::ComboBox()); this->label5 = (gcnew System::Windows::Forms::Label()); this->comboBox2 = (gcnew System::Windows::Forms::ComboBox()); this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->label7 = (gcnew System::Windows::Forms::Label()); this->label6 = (gcnew System::Windows::Forms::Label()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); this->checkBox2 = (gcnew System::Windows::Forms::CheckBox()); this->button6 = (gcnew System::Windows::Forms::Button()); this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip()); this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->fileToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->settingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->decoderzToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->creditsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->decoderzToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->label8 = (gcnew System::Windows::Forms::Label()); this->groupBox1->SuspendLayout(); this->menuStrip1->SuspendLayout(); this->SuspendLayout(); // // listView1 // this->listView1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle; this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(2) {this->columnHeader1, this->columnHeader2}); this->listView1->Font = (gcnew System::Drawing::Font(L"Courier New", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->listView1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ListViewItem^ >(1) {listViewItem2}); this->listView1->Location = System::Drawing::Point(2, 91); this->listView1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->listView1->Name = L"listView1"; this->listView1->Size = System::Drawing::Size(161, 241); this->listView1->TabIndex = 0; this->listView1->UseCompatibleStateImageBehavior = false; this->listView1->View = System::Windows::Forms::View::Details; // // columnHeader1 // this->columnHeader1->Text = L"Address"; this->columnHeader1->Width = 80; // // columnHeader2 // this->columnHeader2->Text = L"Value"; this->columnHeader2->Width = 80; // // button1 // this->button1->Location = System::Drawing::Point(94, 340); this->button1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(69, 30); this->button1->TabIndex = 1; this->button1->Text = L"Add item"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->textBox1->Location = System::Drawing::Point(218, 135); this->textBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(265, 22); this->textBox1->TabIndex = 2; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(215, 118); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(37, 13); this->label1->TabIndex = 3; this->label1->Text = L"Value:"; // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(-3, 74); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(43, 13); this->label2->TabIndex = 4; this->label2->Text = L"Found: "; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(46, 74); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(13, 13); this->label3->TabIndex = 5; this->label3->Text = L"0"; // // button2 // this->button2->Location = System::Drawing::Point(275, 339); this->button2->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(54, 49); this->button2->TabIndex = 6; this->button2->Text = L"Clear items"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button3 // this->button3->Location = System::Drawing::Point(186, 89); this->button3->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(75, 25); this->button3->TabIndex = 7; this->button3->Text = L"First Scan"; this->button3->UseVisualStyleBackColor = true; // // button4 // this->button4->Location = System::Drawing::Point(267, 89); this->button4->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(75, 25); this->button4->TabIndex = 8; this->button4->Text = L"Next Scan"; this->button4->UseVisualStyleBackColor = true; // // button5 // this->button5->Location = System::Drawing::Point(408, 89); this->button5->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->button5->Name = L"button5"; this->button5->Size = System::Drawing::Size(75, 25); this->button5->TabIndex = 9; this->button5->Text = L"Undo Scan"; this->button5->UseVisualStyleBackColor = true; // // checkBox1 // this->checkBox1->AutoSize = true; this->checkBox1->Location = System::Drawing::Point(169, 135); this->checkBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->checkBox1->Name = L"checkBox1"; this->checkBox1->Size = System::Drawing::Size(45, 17); this->checkBox1->TabIndex = 10; this->checkBox1->Text = L"Hex"; this->checkBox1->UseVisualStyleBackColor = true; // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(169, 173); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(65, 13); this->label4->TabIndex = 11; this->label4->Text = L"Scan Type: "; // // comboBox1 // this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox1->FormattingEnabled = true; this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(1) {L"Exact Value"}); this->comboBox1->Location = System::Drawing::Point(233, 165); this->comboBox1->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->comboBox1->Name = L"comboBox1"; this->comboBox1->Size = System::Drawing::Size(167, 21); this->comboBox1->TabIndex = 12; // // label5 // this->label5->AutoSize = true; this->label5->Location = System::Drawing::Point(169, 200); this->label5->Name = L"label5"; this->label5->Size = System::Drawing::Size(67, 13); this->label5->TabIndex = 13; this->label5->Text = L"Value Type: "; // // comboBox2 // this->comboBox2->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox2->FormattingEnabled = true; this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^ >(1) {L"4 Bytes"}); this->comboBox2->Location = System::Drawing::Point(233, 193); this->comboBox2->Name = L"comboBox2"; this->comboBox2->Size = System::Drawing::Size(167, 21); this->comboBox2->TabIndex = 14; // // groupBox1 // this->groupBox1->Controls->Add(this->textBox3); this->groupBox1->Controls->Add(this->textBox2); this->groupBox1->Controls->Add(this->label7); this->groupBox1->Controls->Add(this->label6); this->groupBox1->Location = System::Drawing::Point(233, 223); this->groupBox1->Name = L"groupBox1"; this->groupBox1->Size = System::Drawing::Size(167, 109); this->groupBox1->TabIndex = 15; this->groupBox1->TabStop = false; this->groupBox1->Text = L"Memory Scan Options"; // // textBox3 // this->textBox3->Font = (gcnew System::Drawing::Font(L"Courier New", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->textBox3->Location = System::Drawing::Point(42, 49); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(119, 22); this->textBox3->TabIndex = 3; this->textBox3->Text = L"ffffffff"; this->textBox3->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox2 // this->textBox2->Font = (gcnew System::Drawing::Font(L"Courier New", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->textBox2->Location = System::Drawing::Point(42, 23); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(119, 22); this->textBox2->TabIndex = 2; this->textBox2->Text = L"00000000"; this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // label7 // this->label7->AutoSize = true; this->label7->Location = System::Drawing::Point(7, 48); this->label7->Name = L"label7"; this->label7->Size = System::Drawing::Size(29, 13); this->label7->TabIndex = 1; this->label7->Text = L"Stop"; // // label6 // this->label6->AutoSize = true; this->label6->Location = System::Drawing::Point(7, 26); this->label6->Name = L"label6"; this->label6->Size = System::Drawing::Size(29, 13); this->label6->TabIndex = 0; this->label6->Text = L"Start"; // // timer1 // this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); // // checkBox2 // this->checkBox2->AutoSize = true; this->checkBox2->Location = System::Drawing::Point(415, 191); this->checkBox2->Name = L"checkBox2"; this->checkBox2->Size = System::Drawing::Size(68, 17); this->checkBox2->TabIndex = 17; this->checkBox2->Text = L"TopMost"; this->checkBox2->UseVisualStyleBackColor = true; // // button6 // this->button6->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button6.BackgroundImage"))); this->button6->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Zoom; this->button6->Location = System::Drawing::Point(2, 27); this->button6->Name = L"button6"; this->button6->Size = System::Drawing::Size(38, 35); this->button6->TabIndex = 18; this->button6->UseVisualStyleBackColor = true; this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click); // // menuStrip1 // this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->fileToolStripMenuItem, this->fileToolStripMenuItem1, this->helpToolStripMenuItem, this->creditsToolStripMenuItem}); this->menuStrip1->Location = System::Drawing::Point(0, 0); this->menuStrip1->Name = L"menuStrip1"; this->menuStrip1->Size = System::Drawing::Size(495, 24); this->menuStrip1->TabIndex = 19; this->menuStrip1->Text = L"menuStrip1"; // // fileToolStripMenuItem // this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem"; this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20); this->fileToolStripMenuItem->Text = L"File"; // // fileToolStripMenuItem1 // this->fileToolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->settingsToolStripMenuItem}); this->fileToolStripMenuItem1->Name = L"fileToolStripMenuItem1"; this->fileToolStripMenuItem1->Size = System::Drawing::Size(39, 20); this->fileToolStripMenuItem1->Text = L"Edit"; // // settingsToolStripMenuItem // this->settingsToolStripMenuItem->Name = L"settingsToolStripMenuItem"; this->settingsToolStripMenuItem->Size = System::Drawing::Size(116, 22); this->settingsToolStripMenuItem->Text = L"Settings"; // // helpToolStripMenuItem // this->helpToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->decoderzToolStripMenuItem1}); this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem"; this->helpToolStripMenuItem->Size = System::Drawing::Size(44, 20); this->helpToolStripMenuItem->Text = L"Help"; // // decoderzToolStripMenuItem1 // this->decoderzToolStripMenuItem1->Name = L"decoderzToolStripMenuItem1"; this->decoderzToolStripMenuItem1->Size = System::Drawing::Size(123, 22); this->decoderzToolStripMenuItem1->Text = L"Decoderz"; // // creditsToolStripMenuItem // this->creditsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->decoderzToolStripMenuItem}); this->creditsToolStripMenuItem->Name = L"creditsToolStripMenuItem"; this->creditsToolStripMenuItem->Size = System::Drawing::Size(56, 20); this->creditsToolStripMenuItem->Text = L"Credits"; // // decoderzToolStripMenuItem // this->decoderzToolStripMenuItem->Name = L"decoderzToolStripMenuItem"; this->decoderzToolStripMenuItem->Size = System::Drawing::Size(123, 22); this->decoderzToolStripMenuItem->Text = L"Decoderz"; // // label8 // this->label8->AutoSize = true; this->label8->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->label8->ForeColor = System::Drawing::Color::Red; this->label8->Location = System::Drawing::Point(183, 27); this->label8->Name = L"label8"; this->label8->Size = System::Drawing::Size(120, 16); this->label8->TabIndex = 20; this->label8->Text = L"No Process Select"; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(495, 467); this->Controls->Add(this->label8); this->Controls->Add(this->button6); this->Controls->Add(this->checkBox2); this->Controls->Add(this->groupBox1); this->Controls->Add(this->comboBox2); this->Controls->Add(this->label5); this->Controls->Add(this->comboBox1); this->Controls->Add(this->label4); this->Controls->Add(this->checkBox1); this->Controls->Add(this->button5); this->Controls->Add(this->button4); this->Controls->Add(this->button3); this->Controls->Add(this->button2); this->Controls->Add(this->label3); this->Controls->Add(this->label2); this->Controls->Add(this->label1); this->Controls->Add(this->textBox1); this->Controls->Add(this->button1); this->Controls->Add(this->listView1); this->Controls->Add(this->menuStrip1); this->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog; this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon"))); this->MainMenuStrip = this->menuStrip1; this->Margin = System::Windows::Forms::Padding(3, 4, 3, 4); this->Name = L"Form1"; this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; this->Text = L"[DZ Engine] - Decoderz"; this->groupBox1->ResumeLayout(false); this->groupBox1->PerformLayout(); this->menuStrip1->ResumeLayout(false); this->menuStrip1->PerformLayout(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this->listView1->Items->Add(this->textBox1->Text); this->listView1->Items[0]->SubItems->Add("Aldo"); test(); //textBox1->Clear; } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { this->listView1->Items->Clear(); } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) { form2->Show(); } }; }
Atenciosamente.
Decoderz
Todas as Respostas
-
Crie uma instância do form cada vez que for abrir.
Form2^ form2 = gcnew Form2(); form2->Show();
Tire o código do construtor e a variável pública.
- Editado Vitor dos Santos quarta-feira, 2 de maio de 2012 21:45