views:

95

answers:

1

Hi all,

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

A: 

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();
kgiannakakis
hithanks for the reply but i m still confused about how i will go to the first form if i am at unknown level of hierarchy. the situation is that if the objects of the same class are at the top of one and another. So is there any way i can keep the reference of the first from and pop the forms to that level whenever required.regards,madhup
Madhup
The easiest way is to create a singleton class that will hold a reference to your parent form. Then from anywhere you could call MyAppManager.Instance.MainForm.Show();
kgiannakakis