I have two Windows Forms, say, FormA and FormB. FormA should load first, as in Application.Run(gcnew FormA()); FormA has button A which when clicked should take me to FormB. Similarly, FormB has button B which when clicked should take me back to FormA. Where and how should I create FormB and how should I code the click events for A and B. I would be very grateful for all help.
Loading
ray donaPosted Dec 10, 2008, 11:13 AM
Alan,
Many thanks for your reply. I used the code you gave and the program worked fine. Every time I build now I get this compiler warning. It doesn't affect the program in any way. I just wondered if you knew any way of getting rid of it? :-
Error Messages for Windows Forms
Visual Studio cannot open a designer for the file because the class within it does not inherit from a class that can be visually designed
Visual Studio loaded the class, but the designer for that class could not be loaded.
The class can be designed, but it is not the first class in the file. Visual Studio requires that designers use the first class in the file.
To correct this error
·
Move the class code so that it is the first class in the file, and then load the designer again.AlanPosted Dec 1, 2008, 4:29 PM
After you've created the project for FormA, add FormB as follows:
Project menu -> Add New Item -> UI -> Windows Form
and then add button B to it.
In FormA.h insert this line at the top of the file:
#include "FormB.h"
Now double click on button A in the designer and insert the following code in its Click eventhandler:
private: System::Void A_Click(System::Object^ sender, System::EventArgs^ e)
{
FormB^ formB = gcnew FormB();
formB->Show();
this->Hide();
}
Finally double click on button B in the designer and insert the following code in its Click eventhandler:
private: System::Void B_Click(System::Object^ sender, System::EventArgs^ e)
{
Form^ formA = Application::OpenForms["FormA"];
formA->Show();
this->Close();
}