Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Been trying things like this

 

Dim FormNeedDrawings As New frmUserMessages


If FormNeedDrawings Is Nothing Then FormNeedDrawings.Show()
'=============
If FormNeedDrawings.Visible = False Then FormNeedDrawings.Show()

 

Can't get it to work &

Can' find anything on this...

 

Mark

  • *Experts*
Posted

Im not really sure what you are looking for but this might help you:

Dim someform As New Form
'.....
'.....
If someform.Created Then 'The Created property will tell you if the form is opened
   'The form was opened
End If

Posted

It don't work either

 

Dim FormNeedDrawings As New frmUserMessages

If Not FormNeedDrawings.Created Then FormNeedDrawings.Show()

 

Each time this routine is run this form will keep opening multiply times until I have x many of them. I want the routine to stop the show process if the form is currently open one time.

 

But, thanks for the tip on "created" I didn't know anything about it cause it don't show up in the popup intelesense menu....

 

Mark

  • *Experts*
Posted

I think im beginning to understand your problem now :).

You are creating a new instance of the form everytime, so no matter what kind of an approach to take at checking if the form is open, it will always be closed. What you could do it have one variable of your form's type and use only that one without creating any new ones (you could make it shared for example).

Posted

mutant, that makes sense to me. Do you mean create the instance at module level? This function I am using is in a module.

 

I put the creation of the form in the top of the module and it worked right the first time. But the next time it should have opened the form, I got the following unhandled exception:

"Can not access a disposed object named frmUserMessage"

 

So I take it, since I used the me.close to close it, the GC ate up the instance I created. So, using me.close to close it defeats all logic to the function...

 

What are your thoughts?

 

Mark

Posted

It looks like this

 

Module Module1
Public FormNeedDrawings As New frmUserMessages

   Function IsDatabaseUpToDate() As Boolean      
       If Not FormNeedDrawings.Created Then FormNeedDrawings.Show()
           Return False
       End If
       Return True
   End Function

End Module


'===================================
'and when I'm done with the form I close it like this
Me.Close

  • *Experts*
Posted

If you want to open the form again, simply use the Hide() method instead of show so its not released from memory yet and you can use Show again.

Something along those lines would work, but a class with shared members would be better :).

Posted

Thanks. I would rather unload the form. Could please explain a class with shared members or give a simple example please.

 

Dealing with these non public forms has really been a headache for me to learn

 

thanks

 

Mark

Posted

I use this method when dealing with MDI forms.

 

Have a global variable, say gblnIsFormOpen.

 

Set to true when open.

 

Test to see if this variable is true before calling Show. If it is true, don't call Show.

 

Remember to set variable to False when the form closes tho:)

My website
Posted

I have posted this sample code on other thread that seeks if there's other form created like the one you want to create...

 

If so, it doesn't create the new one and focus the alreay created...

 

This is usefull if, for example, you want to insure that only one instance of you app is running per computer...

 

http://www.xtremedotnettalk.com/t78704.html

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
Posted

Thanks Alex, I have already found that and TOOK it. It is great code and I made a module just for it to use on the main app.

 

Hog, I don't know why I didn't think of that. It seems to be the only way of doing it without hiding and showing the form repeatedly

 

Thanks a million guys

 

Mark

Posted

For the hog's method...

It can be wuite painfull if you have an app with a lot of forms. You'll have to create a var, that will act as a flag, for each one of them...

 

You can tune this by implementing the same thing but with an HashTable:

 

       Dim htFormIsCreated As New Hashtable

       'To add a form
       htFormIsCreated.Add(Form1, True)

       'To ask if the form is created and show or not the form
       If Not htFormIsCreated(Form1) Then
           Form1 = New System.Windows.Forms.Form
           Form1.Show()
       End If

This is just a sample, it can be tunned but I think in time it will become more intuitive to understand...

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
Posted

Thanks Alex. I will add that to my code library and use it in the future as well. But for the time being, I am going to use Hog's example with the Boolean variable as I only have one form that concerns me on this project.

 

Thanks all for your contributions.....

 

Mark

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