'How do i make a log in and welcome page without including each header within the other? (C++/cli)
I have a button in "MyForm" named button_1, that, when clicked, will open up a "welcome page" ("Page"). This is how I have it set up.
In Page.h:
private: Form^ frontpage;
public:
Page(Form^ f) {
frontpage = f;
InitializeComponent();
}
In MyForm.h, under button1_Click:
if (userString.Log_in::usernameExists(usernameInfo) && userString.Log_in::readPassword(usernameInfo, passInfo)) {
//open new form here
Page^ form2 = gcnew Page(this);
form2->Show();
}
It works exactly like it needs to, however...
I need the username variable used in MyForm to be displayed on the welcome page. I have tried several methods, but ultimately none of them initialize properly.
One method (note: it may not be efficient but I want the program to work): Under button1_Click (MyForm.h), before the code opening the second form:
std::ofstream baton("relay.txt");
baton << usernameInfo;
I make a new file and store the username there. The idea is to open the same file, read it and grab the variable from there. Not my favorite solution and I'd very much like to hear alternatives. The next step would be to make a custom event (in Page.h) so I can place this inside the function:
std::string Baton;
std::fstream onyourmarks;
onyourmarks.open("relay.txt");
std::getline(onyourmarks, Baton);
String^ finishline = gcnew String(Baton.c_str());
But I am having a lot of trouble figuring out how to write an event that would trigger upon the second form opening. The event needs to be triggered either by button1_Click or it should run as soon as the second form is opened. I haven't really tried figuring out how to write it in button1_Click because I need the variable in Page.h, and I can't #include "MyForm.h" in Page because Page is already included in MyForm. I am sorry if this question is ridiculous, I'm in a self-paced class by myself and I don't have a teacher or peers to ask!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
