FartNocker Posted January 15, 2004 Posted January 15, 2004 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 Quote
Administrators PlausiblyDamp Posted January 15, 2004 Administrators Posted January 15, 2004 If formneedsdrawing.visible = false will tell you if the form is hidden or not. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 No the form is not hidden because it has never been opened before and when it is opened, then the close method is called so the Visible thing don't work But thanks Mark Quote
*Experts* mutant Posted January 15, 2004 *Experts* Posted January 15, 2004 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 Quote
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 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 Quote
*Experts* mutant Posted January 15, 2004 *Experts* Posted January 15, 2004 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). Quote
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 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 Quote
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 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 Quote
*Experts* mutant Posted January 15, 2004 *Experts* Posted January 15, 2004 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 :). Quote
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 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 Quote
samsmithnz Posted January 15, 2004 Posted January 15, 2004 If VB6 we used to look at the Forms collection to see if a form was loaded. Is this the sort of functionality you're looking for in VB.NET now? Quote Thanks Sam http://www.samsmith.co.nz
hog Posted January 15, 2004 Posted January 15, 2004 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:) Quote My website
AlexCode Posted January 15, 2004 Posted January 15, 2004 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 Quote Software bugs are impossible to detect by anybody except the end user.
FartNocker Posted January 15, 2004 Author Posted January 15, 2004 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 Quote
AlexCode Posted January 15, 2004 Posted January 15, 2004 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 Quote Software bugs are impossible to detect by anybody except the end user.
hog Posted January 15, 2004 Posted January 15, 2004 AlexCode: sweet:) so much nicer than the way I do it! I shall use this method in future:) Quote My website
FartNocker Posted January 16, 2004 Author Posted January 16, 2004 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 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.