kaisersoze Posted January 28, 2004 Posted January 28, 2004 This part of code is written on a click event of a menu. Dim obj_frmSearch As New frmSearch() obj_frmSearch.MdiParent = Me obj_frmSearch.Show() Everytime I click on the same menu a new instance is created and a form is loaded on the old form. Is there a way to do like this: If the form is not creatyed then create and show else if it is already created then bring (show) that form on the top. Please... Quote Note: I think as a programmer not as a human, so use my answer at your will
*Experts* mutant Posted January 28, 2004 *Experts* Posted January 28, 2004 You could declare and assign the instance to a private varibale in your form and simply call the Show method in your button click event if you only want one instance. One other method would be to keep a boolean variable in your form and set it to true when you open a form, and in your event check if false and create new form, else do not create a new form. Yet another method would be to enumerate all the MDI children and see if any form in there is of the same type or with the same name: For Each f As Form In Me.MDIChildren If TypeOf f Is YourFormType Then 'form of that type already open End If Next Simply saying, there is many possibilities :). Quote
NK2000 Posted January 28, 2004 Posted January 28, 2004 so you should use a bool and set it to true if it finds something if the bool is after the for each still false then you can open your window :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.