Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Note: I think as a programmer not as a human, so use my answer at your will
  • *Experts*
Posted

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 :).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...