开发者

Logout Option In Application

I have developed a windows based application using VB.NET 2005. It is 开发者_开发技巧working perfectly fine. Now the client wants to add an option called "Logout". When this is selected, all the open windows forms should get closed, the MDI form need to get opened with the login form on top of it.

Can anyone please suggest as to what can be done to sort out this matter.


Are you manually keeping track of the forms that are opened by your application? If so, it's a simple matter of closing all of the forms that have been opened since the last login.

Otherwise, I suggest looping through all of the forms currently open in your application using the Application.OpenForms property provided by .NET. In the loop, you want to check each form against your MDI form (because you want that form to remain open, no matter what), and if it's not the MDI form, close it:

For Each frm As Form In Application.OpenForms
   If frm IsNot MyMDIForm Then
      frm.Close()
      frm.Dispose()
   End If
Next frm

After you've closed all of the open forms (except for your MDI form), you'll want to place any additional code needed to log out the user (closing database connections, saying goodbye, etc.)

Finally, you want to end with the login form displayed, and because you probably won't want the user to be able to interact with any of the controls on the MDI form until they are logged in, you need to display the login form as a modal dialog. A modal dialog basically takes over control of your application so that the user cannot click on any other forms until the modal dialog is closed. To display a form as a modal dialog, use the ShowDialog method of the form you want to display, passing its parent/owner form as an argument:

LoginForm.ShowDialog(MyMDIForm)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜