Need Help With Win Forms
-
I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:
if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
{
//TODO1: set up logic for authentic use
copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
}This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science
-
I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:
if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
{
//TODO1: set up logic for authentic use
copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
}This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science
-
I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false. The form is a basic logon screen that is supposed to return "true" to the Main form, and the main form is supposed to display itself. However the only way to get the main form to display itself is if I code the following:
if (!AuthenticUser) //TODO 3: NOTE - this is logically incorrect, but it works!
{
//TODO1: set up logic for authentic use
copyrightRichTextBox.LoadFile(@"..\..\Supporting Files\Copyright.rtf");
}This doesn't make logical sense to me. Can someone explain what may be happening here? Thanks. :confused: Dre---
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science
DRAYKKO wrote:
I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false.
You're probably setting the property on a different instance of the form. Can you post that code ? The code that sets the value of Authenticated user is what we really need to see here, I suspect.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
DRAYKKO wrote:
I'm trying to figure out why it is, when I close one form - which is supposed to set a property in my Main form to true - the property reverts back to false.
You're probably setting the property on a different instance of the form. Can you post that code ? The code that sets the value of Authenticated user is what we really need to see here, I suspect.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
private void OK_Click(object sender, EventArgs e)
{
//use this to confirm that the user is valid
Main userAuthentication = new Main();userAuthentication.AuthenticUser = CheckUser(); if (userAuthentication.AuthenticUser) { this.Close(); } else { if (Tries < 2) { MessageBox.Show("That was an invalid user name or password. Try again..."); ++Tries; CheckUser(); } else { userAuthentication.AuthenticUser = false; this.Close(); } } } public bool CheckUser() { //testing number of tries //string numberOfTries = string.Format("tries = {0}", Tries); //MessageBox.Show(numberOfTries); if ((usernameTextBox.Text == "User1") && (passwordTextBox.Text == "User1")) return true; else if ((usernameTextBox.Text == "User2") && (passwordTextBox.Text == "User2")) return true; else { usernameTextBox.Text = ""; passwordTextBox.Text = ""; usernameTextBox.Focus(); return false; } }
This code, from the Logon form, is supposed to alert the Main form whether the user typed in a valid username and password. And when I "trace" it, it does set AuthenicUser to true. But it seems that when I close the logon form the property reverts back to false (and I'm not sure why). BTW: Is there a way to send attachments here?
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science
-
private void OK_Click(object sender, EventArgs e)
{
//use this to confirm that the user is valid
Main userAuthentication = new Main();userAuthentication.AuthenticUser = CheckUser(); if (userAuthentication.AuthenticUser) { this.Close(); } else { if (Tries < 2) { MessageBox.Show("That was an invalid user name or password. Try again..."); ++Tries; CheckUser(); } else { userAuthentication.AuthenticUser = false; this.Close(); } } } public bool CheckUser() { //testing number of tries //string numberOfTries = string.Format("tries = {0}", Tries); //MessageBox.Show(numberOfTries); if ((usernameTextBox.Text == "User1") && (passwordTextBox.Text == "User1")) return true; else if ((usernameTextBox.Text == "User2") && (passwordTextBox.Text == "User2")) return true; else { usernameTextBox.Text = ""; passwordTextBox.Text = ""; usernameTextBox.Focus(); return false; } }
This code, from the Logon form, is supposed to alert the Main form whether the user typed in a valid username and password. And when I "trace" it, it does set AuthenicUser to true. But it seems that when I close the logon form the property reverts back to false (and I'm not sure why). BTW: Is there a way to send attachments here?
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science
DRAYKKO wrote:
Main userAuthentication = new Main();
Like I thought. You're creating a new instance of the Main class, which has absolutely NOTHING to do with the instance in which you check this variable. You should create a variable inside this form and check it from your main instance, when you close the login dialog. Or, set up a delegate that gets called if login is successful.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
DRAYKKO wrote:
Main userAuthentication = new Main();
Like I thought. You're creating a new instance of the Main class, which has absolutely NOTHING to do with the instance in which you check this variable. You should create a variable inside this form and check it from your main instance, when you close the login dialog. Or, set up a delegate that gets called if login is successful.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thank you Christian! I see the problem now. :doh: As a solution I made the property and it's subsequent variable static bool (rather than just bool), so that they were accessible from the Logon form. Thanks for your input, and help!! :) Dre---
======================= Every experience in life is a lesson to be learned A. Stevens B.S., Computer Science