R – go back to the first form in windows mobile application

formswindows-mobile

i am developing an application in which i have a logout option at all the forms. When i click that button I have to return to login form which is the first form to be displayed . So i am able to track back to the first from by making a new object of this from by the way this idea is bad to implement because the other froms are also in the stack. My question is how will i go to that first form while the other form objects are distroyed.

The whole idea is about login-logout functionality in winMo app. If somebody can help me with some part of code it will be very great.

Regards,
Madhup

Best Answer

The easiest way is to pass a reference to the Log-in form to all other forms. Avoid creating and destroying forms. Since you know you are going to reuse them, create them only once and then show or hide them.

In log-in form:

if (isLoginSuccessfull) {
   newForm.SetParentForm(this);
   newForm.Show();
   // Do not call Close();
}

In secondary-forms:

public void SetParentForm(Form parent) {
  this.parent = parent;
}

// When you need to close the form:
parent.Show();
Related Topic