How to show a form that needs to be hidden immediately.


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Just noticed that I never let y'all know what I actually did. I ended up adding a method to the form to show the browse dialog, then if the dialog returns OK, show the form. Sort of a combo between what I was trying and what Trent suggested:



' In the form that I wanted hidden...

Public Sub Search()

  ' Open search form, test for OK

  Using myBrw As New MyBrowseDialog()

    If myBrw.ShowDialog() = DialogResult.OK Then

      Me.Show()

    Else

      Me.Close

    End If

  End Using

End Sub




And it is called like this

' To run a search...

Dim frm As New MyForm()

frm.Search()

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
When I have the need for this, I take a different approach.  First, show the BrowseDialog THEN show the form.  It would look something like this:

Dim myBrw As New MyBrowseDialog()
Dim myBO As New MyBO()
Dim myForm as MyForm

'-- Set the BO to populate (otherwise an error will occur)
myBrw.BusinessObjectToPopulate = myBO

'-- Show the Browse
If myBrw.ShowDialog() = OK Then
    '-- Create and show the form.  Pass over the populated BO and then just do a CopyDataFrom in the Constructor
    '-- of the form.
    myForm = New MyForm(myBO)

    '-- Now show the dialog or show it in your MDI (whatever your need is)
    myForm.ShowDialog()
End If


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Nope, that won't work as this is being called in a class that isn't a form at all. Pinch



I've also tried:



- setting the location off the screen (-3200,-3200)

- setting the size to zero

- locking the MDI parent form using ScreenLock

- minimizing the form

- calling visible before show

- Hiding the form in the VisibleChanged event



Nothing worked. In every case, there is a brief moment when the form is shown before going away.



I'm still curious if this can be done, so if anyone has any thoughts I'd love to hear them!



However, my understanding of garbage collection wasn't complete. I assumed that the parent form would stick around after the search form was closed. Then I got the brilliant idea to actually test this and put a breakpoint in the dispose method (hey what can I say...apparently both brain cells are active today). Turns out that when the search form is closed, before the main form has been shown, it is disposed of immediately! There was no problem to solve! DOH! Pinch



Thanks for your help though, Edhy. It did get me thinking, which lead to some google searches that lead to the other brain cell firing. w00t
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
What about something like this:

Public Shared Sub OpenMyForm(ByVal projectID As Integer)

     MicroFour.StrataFrame.Tools.LockScreen.Lock(Me)

     Dim frm As New MyForm(projectID)

     frm.MDIParent = MainForm

     frm.Visible = False

     MicroFour.StrataFrame.Tools.LockScreen.Unlock()

     ' This method on the form calls the search form

     frm.Search()

End Sub



Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, I'm probably even more confused. Here's what I'm trying to do:



I've written my own "browse" dialog (long story) and want to be able to open a form, show that dialog, not the form. The user then does a search, selects one or more records and clicks a "view" button. At this point my form loads those records into its BO and is shown.



However, I needed to handle the case were the user closes the search form before selecting any records to open. My concern was that if I didn't show the form, it wouldn't get garbage collected. I'm using code like this to open the form:



Public Shared Sub OpenMyForm(projectID as integer)

Dim frm As New MyForm(projectID)

frm.MDIParent = MainForm

' This method on the form calls the search form

frm.Search()

End Sub




I was originally just showing my search dialog before I'd loaded the form (before the Show() method had been called). Maybe this is OK?



Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Greg,

I am a bit confused here, when you create the instance of the form, it is not visible, so you should have access to it before you set it form.Visible = True.

Also the lock method are to be work not in the form itself, but in the calling class where you are creating your form, so it will lock that view, your form will be created, then will unlock the previous locked view.

How are you calling your form?

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks Edhy. I didn't know that one existed (or forgot about it).



It's not working though. Here is the code that I tried. It still shows the form, at least the outline of it before it is hidden.



MicroFour.StrataFrame.Tools.LockScreen.Lock(Me)

Me.Show()

Me.Visible = False

MicroFour.StrataFrame.Tools.LockScreen.UnLock()




Any other ideas?
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Greg,

How about wrapping your code with a LockScreen:

MicroFour.StrataFrame.Tools.LockScreen.Lock(Me)

... Your code

MicroFour.StrataFrame.Tools.LockScreen.UnLock()



Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I have a form that I'd like to load, but have it hidden immediately. I'm currently just setting visible to False after it's done loading, but there is flicker. Is there a suggested way to do this.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search