开发者

How does a form know when you are logged in?

Ok next,

I got 2 forms, login form and main form, when i press login on the mainform, the loginform show up.

On the login form you can create a account, the textbox values are entered in xml file and uploaded to a ftp server.

Wen you want to login it reads the xml if the username and password are correct, then the login form closes, and o开发者_运维技巧n the mainform labels would change to ' logged in',....

How do i solve this??


You open the Login form as an Modal and return an result depending on what ever login was successful or not.

Something like this: Link


I think the problem you are having is deciding how to communicate the "logged in" and "not logged in" status of the user between your login form and your Main form.

One way of doing this would be to call a method or function that checks whether the credentials supplied by the user are valid and returns a value that represents whether login was successful or not. You could store this value in a form-level public Field or Property.

You could then write code in the Main form to read this value from the Login form to determine the login status:

Throughout the rest of your Main form, you could then set the text of your controls appropriately based on the login status:

if (userIsLoggedIn == true)
    { label1.Text = "Logged In" } 
else 
    { label1.Text = "Not Logged In" }

EDIT: In your Login form, you define a property (let's call it IsLoggedIn) which stores the login status. This can be a simple Boolean (true/false) value. You are opening the login form from your Main form - this means that you must have code that creates a new instance of the login form and displays it. Something like (C#):

LoginForm login = new LoginForm();
login.ShowDialog();

if (login.IsLoggedIn)
{
// update labels to Logged In
}
else
{
// update labels to not Logged In
}

In the login form your code does the login checking and you store the result as follows:

// if successful, set logged in status to true

this.IsLoggedIn = true;


You could always fire an event when the login form closes.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜