Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close visible form as new menu item chosen

Status
Not open for further replies.

chapm4

IS-IT--Management
Nov 12, 2001
38
0
0
US
Dumb question as it seems I have a lot of.....I have an app using mdi dropdown menu's that open various forms. When a new item is chosen, I want the old window to close (If the user did not use the quit button on the form). How do I do this and where?
 
maybe you should not be using MDI for your application. Remember M in MDI stands for Mutiple.

Anyway, here is one way to do it. (Although I think there is a proper way, but do not remember what it is.)

Private frmActive As Windows.Forms.Form

...

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

Try
frmActive.Close()
Catch
End Try

Dim x As New frmColorText()
frmActive = x
x.MdiParent = Me
x.Show()

End Sub

This will close the last window of the same menuitem that was opened. Add this to each menuitem with the same variable and it will keep only one window open at a time.

Kris
[borg2]
 
Thanks alot for the help. This works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top