掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Form1とFrom2を往復(画面遷移)する方法は? (ID:70434)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
メニューがあるのであれば、メニューで遷移させた方が妥当ではないでしょうか? 具体例 1.MyForm.hを追加 #pragma once namespace test { public ref class MyForm : public System::Windows::Forms::Form { public: enum class NEXTTYPE { FORM1, FORM2, MENU }; protected: NEXTTYPE NextType_; public: MyForm() : NextType_(NEXTTYPE::MENU), Form() {} property NEXTTYPE NextType { void set(NEXTTYPE type) { NextType_ = type; } NEXTTYPE get() { return NextType_; } } }; } 2.Form1,Form2の継承元をMyFormに変更(要MyForm.hのインクルード) 3.Form1のボタンの処理 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { // Form2へ this->NextType = NEXTTYPE::FORM2; this->Close(); } System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { // メニューへ this->NextType = NEXTTYPE::MENU; this->Close(); } }; 4.Form2のボタンの処理 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { // Form1へ this->NextType = NEXTTYPE::FORM1; this->Close(); } System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { // メニューへ this->NextType = NEXTTYPE::MENU; this->Close(); } }; 5.MenuForm(main関数でApplication::Run(gcnew MenuForm());となる)のボタンの処理 #include "Form1.h" #include "Form2.h" ・ ・ ・ private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { MyForm::NEXTTYPE type = MyForm::NEXTTYPE::FORM1; // メニューを非表示に this->Hide(); while (1) { MyForm^ form; switch (type) { case MyForm::NEXTTYPE::FORM1: // Form1へ form = gcnew Form1(); break; case MyForm::NEXTTYPE::FORM2: // Form2へ form = gcnew Form2(); break; default: // メニューへ戻る form = nullptr; break; } if (form == nullptr) { break; } form->ShowDialog(); type = form->NextType; delete form; } // メニューを表示 this->Show(); } };
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.